Best JavaScript code snippet using qawolf
send-email.test.js
Source:send-email.test.js
...43 expect(notifyClient).toHaveBeenCalledWith(env.notifyApiKey)44 })4546 test('should call validateEmail when a valid message is received', async () => {47 await sendEmail(mockContext, mockMessage)4849 expect(validateEmail).toHaveBeenCalled()50 })5152 test('should call validateEmail with default emailAddress when sendEmail is called without a given emailAddress', async () => {53 await sendEmail(mockContext, mockMessage)5455 expect(validateEmail).toHaveBeenCalledWith(mockContext, defaultEmailAddress)56 })5758 test('should not reject on validateEmail with default emailAddress when sendEmail is called without a given emailAddress', async () => {59 await sendEmail(mockContext, mockMessage)6061 expect(validateEmail).not.toThrow()62 })6364 test('should not reject with default emailAddress when sendEmail is called without a given emailAddress', async () => {65 const wrapper = async () => {66 await sendEmail(mockContext, mockMessage)67 }6869 expect(wrapper).not.toThrow()70 })7172 test('should throw an error when validateEmail rejects', async () => {73 validateEmail.mockRejectedValue(new Error('must be a string'))7475 const wrapper = async () => {76 await sendEmail(mockContext, mockMessage)77 }7879 expect(wrapper).rejects.toThrow()80 })8182 test('should throw Error when validateEmail rejects', async () => {83 validateEmail.mockRejectedValue(new Error('must be a string'))8485 const wrapper = async () => {86 await sendEmail(mockContext, mockMessage)87 }8889 expect(wrapper).rejects.toThrow(Error)90 })9192 test('should throw error which starts with "Oh dear" when validateEmail rejects', async () => {93 validateEmail.mockRejectedValue(new Error('must be a string'))9495 const wrapper = async () => {96 await sendEmail(mockContext, mockMessage)97 }9899 expect(wrapper).rejects.toThrowError(/^Oh dear/)100 })101102 test('should call notifyClient.sendEmail when a valid message is received', async () => {103 await sendEmail(mockContext, mockMessage)104105 const notifyClientMockInstance = notifyClient.mock.instances[0]106 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledTimes(1)107 })108109 test('should not call notifyClient.sendEmail with empty reference', async () => {110 await sendEmail(mockContext, mockMessage)111112 const notifyClientMockInstance = notifyClient.mock.instances[0]113 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(env.notifyEmailTemplateId, env.notifyEmailAddress, {114 personalisation: flatten(mockMessage),115 reference: ''116 })117 })118119 test('should call notifyClient.sendEmail with uuid when no reference is provided', async () => {120 await sendEmail(mockContext, mockMessage)121122 const notifyClientMockInstance = notifyClient.mock.instances[0]123 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(env.notifyEmailTemplateId, env.notifyEmailAddress, {124 personalisation: flatten(mockMessage),125 reference: mockReference126 })127 })128129 test('should call notifyClient.sendEmail with correct parameters when a emailAddress and reference are received', async () => {130 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)131132 const notifyClientMockInstance = notifyClient.mock.instances[0]133 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(env.notifyEmailTemplateId, emailAddress, {134 personalisation: flatten(mockMessage),135 reference: mockReference136 })137 })138139 test('should throw error when sendEmail rejects', async () => {140 notifyClient.prototype.sendEmail.mockRejectedValue({ Error: 'Request failed with status code 403' })141142 const wrapper = async () => {143 await sendEmail(mockContext, mockMessage)144 }145146 expect(wrapper).rejects.toThrow()147 })148149 test('should throw Error when sendEmail rejects', async () => {150 notifyClient.prototype.sendEmail.mockRejectedValue({ Error: 'Request failed with status code 403' })151152 const wrapper = async () => {153 await sendEmail(mockContext, mockMessage)154 }155156 expect(wrapper).rejects.toThrow(Error)157 })158159 test('should throw an error which starts with "Oh dear" when sendEmail rejects', async () => {160 notifyClient.prototype.sendEmail.mockRejectedValue({ Error: 'Request failed with status code 403' })161162 const wrapper = async () => {163 await sendEmail(mockContext, mockMessage)164 }165166 expect(wrapper).rejects.toThrowError(/^Oh dear/)167 })168169 test('should call notifyClient.sendEmail with correct event-notifyTemplateId when event-notifyTemplate exists in templateSchema', async () => {170 mockMessage.name = mockEventTemplate.name171 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)172173 const notifyClientMockInstance = notifyClient.mock.instances[0]174 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(mockEventTemplate.notifyTemplateId, emailAddress, {175 personalisation: flatten(mockMessage),176 reference: mockReference177 })178 })179180 test('should not call notifyClient.sendEmail with the env (general/default) notifyEmailTemplateId when event-notifyTemplate exists in templateSchema', async () => {181 mockMessage.name = mockEventTemplate.name182183 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)184185 const notifyClientMockInstance = notifyClient.mock.instances[0]186 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(env.notifyEmailTemplateId, emailAddress, {187 personalisation: flatten(mockMessage),188 reference: mockReference189 })190 })191192 test('should not call notifyClient.sendEmail with event-notifyTemplateId when event-notifyTemplate does not exist in templateSchema', async () => {193 mockEventTemplate.name = 'invalid-payment-request-enrichment-error'194 mockMessage.name = mockEventTemplate.name195196 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)197198 const notifyClientMockInstance = notifyClient.mock.instances[0]199 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(mockEventTemplate.notifyTemplateId, emailAddress, {200 personalisation: flatten(mockMessage),201 reference: mockReference202 })203 })204205 test('should call notifyClient.sendEmail with the env (general) notifyEmailTemplateId when event-notifyTemplate does not exists in templateSchema', async () => {206 mockMessage.name = 'invalid-payment-request-enrichment-error'207208 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)209210 const notifyClientMockInstance = notifyClient.mock.instances[0]211 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(env.notifyEmailTemplateId, emailAddress, {212 personalisation: flatten(mockMessage),213 reference: mockReference214 })215 })216217 test('should call notifyClient.sendEmail with the env (general) notifyEmailTemplateId when event-notifyTemplate does not exists in templateSchema', async () => {218 mockMessage.name = 'invalid-payment-request-enrichment-error'219220 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)221222 const notifyClientMockInstance = notifyClient.mock.instances[0]223 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(env.notifyEmailTemplateId, emailAddress, {224 personalisation: flatten(mockMessage),225 reference: mockReference226 })227 })228229 test('confirm batch-processing-error event-templateId is 0b1871ae-095d-4951-bf7e-1bea39a2c995', async () => {230 eventTemplateId = '0b1871ae-095d-4951-bf7e-1bea39a2c995'231 mockMessage.name = 'batch-processing-error'232233 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)234235 const notifyClientMockInstance = notifyClient.mock.instances[0]236 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(eventTemplateId, emailAddress, {237 personalisation: flatten(mockMessage),238 reference: mockReference239 })240 })241242 test('confirm batch-processing-error event-templateId is not empty string', async () => {243 mockMessage.name = 'batch-processing-error'244245 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)246247 const notifyClientMockInstance = notifyClient.mock.instances[0]248 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(eventTemplateId, emailAddress, {249 personalisation: flatten(mockMessage),250 reference: mockReference251 })252 })253254 test('confirm payment-request-enrichment-error event-templateId is 982b92b2-da06-4c51-8996-33b13dd4ce04', async () => {255 eventTemplateId = '982b92b2-da06-4c51-8996-33b13dd4ce04'256 mockMessage.name = 'payment-request-enrichment-error'257258 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)259260 const notifyClientMockInstance = notifyClient.mock.instances[0]261 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(eventTemplateId, emailAddress, {262 personalisation: flatten(mockMessage),263 reference: mockReference264 })265 })266267 test('confirm payment-request-enrichment-error event-templateId is not empty string', async () => {268 mockMessage.name = 'payment-request-enrichment-error'269270 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)271272 const notifyClientMockInstance = notifyClient.mock.instances[0]273 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(eventTemplateId, emailAddress, {274 personalisation: flatten(mockMessage),275 reference: mockReference276 })277 })278279 test('confirm payment-request-processing-error event-templateId is 6645e4aa-aec9-48d9-a674-aa3b15e9cebb', async () => {280 eventTemplateId = '6645e4aa-aec9-48d9-a674-aa3b15e9cebb'281 mockMessage.name = 'payment-request-processing-error'282283 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)284285 const notifyClientMockInstance = notifyClient.mock.instances[0]286 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(eventTemplateId, emailAddress, {287 personalisation: flatten(mockMessage),288 reference: mockReference289 })290 })291292 test('confirm payment-request-processing-error event-templateId is not empty string', async () => {293 mockMessage.name = 'payment-request-processing-error'294295 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)296297 const notifyClientMockInstance = notifyClient.mock.instances[0]298 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(eventTemplateId, emailAddress, {299 personalisation: flatten(mockMessage),300 reference: mockReference301 })302 })303304 test('confirm payment-request-blocked event-templateId is 3756efe8-d1a4-44aa-ba73-46666ce4dffe', async () => {305 eventTemplateId = '3756efe8-d1a4-44aa-ba73-46666ce4dffe'306 mockMessage.name = 'payment-request-blocked'307308 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)309310 const notifyClientMockInstance = notifyClient.mock.instances[0]311 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(eventTemplateId, emailAddress, {312 personalisation: flatten(mockMessage),313 reference: mockReference314 })315 })316317 test('confirm payment-request-blocked event-templateId is not empty string', async () => {318 mockMessage.name = 'payment-request-blocked'319320 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)321322 const notifyClientMockInstance = notifyClient.mock.instances[0]323 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(eventTemplateId, emailAddress, {324 personalisation: flatten(mockMessage),325 reference: mockReference326 })327 })328329 test('confirm payment-request-submission-error event-templateId is fb29affd-9493-467d-bdcf-7fb96463c15b ', async () => {330 eventTemplateId = 'fb29affd-9493-467d-bdcf-7fb96463c15b'331 mockMessage.name = 'payment-request-submission-error'332333 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)334335 const notifyClientMockInstance = notifyClient.mock.instances[0]336 expect(notifyClientMockInstance.sendEmail).toHaveBeenCalledWith(eventTemplateId, emailAddress, {337 personalisation: flatten(mockMessage),338 reference: mockReference339 })340 })341342 test('confirm payment-request-submission-error event-templateId is not empty string', async () => {343 mockMessage.name = 'payment-request-submission-error'344345 await sendEmail(mockContext, mockMessage, emailAddress, mockReference)346347 const notifyClientMockInstance = notifyClient.mock.instances[0]348 expect(notifyClientMockInstance.sendEmail).not.toHaveBeenCalledWith(eventTemplateId, emailAddress, {349 personalisation: flatten(mockMessage),350 reference: mockReference351 })352 })
...
send_email.js
Source:send_email.js
1/* globals _, SendEmail */2(function() {3 'use strict';4 var KeywordValidator, PendingInstructorTasks,5 createEmailContentTable, createEmailMessageViews, createTaskListTable,6 plantTimeout, statusAjaxError;7 plantTimeout = function() {8 return window.InstructorDashboard.util.plantTimeout.apply(this, arguments);9 };10 statusAjaxError = function() {11 return window.InstructorDashboard.util.statusAjaxError.apply(this, arguments);12 };13 PendingInstructorTasks = function() {14 return window.InstructorDashboard.util.PendingInstructorTasks;15 };16 createTaskListTable = function() {17 return window.InstructorDashboard.util.createTaskListTable.apply(this, arguments);18 };19 createEmailContentTable = function() {20 return window.InstructorDashboard.util.createEmailContentTable.apply(this, arguments);21 };22 createEmailMessageViews = function() {23 return window.InstructorDashboard.util.createEmailMessageViews.apply(this, arguments);24 };25 KeywordValidator = function() {26 return window.InstructorDashboard.util.KeywordValidator;27 };28 this.SendEmail = (function() {29 function SendEmail($container) {30 var sendemail = this;31 this.$container = $container;32 this.$emailEditor = XBlock.initializeBlock($('.xblock-studio_view'));33 this.$send_to = this.$container.find("input[name='send_to']");34 this.$cohort_targets = this.$send_to.filter('[value^="cohort:"]');35 this.$course_mode_targets = this.$send_to.filter('[value^="track:"]');36 this.$subject = this.$container.find("input[name='subject']");37 this.$btn_send = this.$container.find("input[name='send']");38 this.$task_response = this.$container.find('.request-response');39 this.$request_response_error = this.$container.find('.request-response-error');40 this.$content_request_response_error = this.$container.find('.content-request-response-error');41 this.$history_request_response_error = this.$container.find('.history-request-response-error');42 this.$btn_task_history_email = this.$container.find("input[name='task-history-email']");43 this.$btn_task_history_email_content = this.$container.find("input[name='task-history-email-content']");44 this.$table_task_history_email = this.$container.find('.task-history-email-table');45 this.$table_email_content_history = this.$container.find('.content-history-email-table');46 this.$email_content_table_inner = this.$container.find('.content-history-table-inner');47 this.$email_messages_wrapper = this.$container.find('.email-messages-wrapper');48 this.$btn_send.click(function() {49 var body, confirmMessage, displayTarget, fullConfirmMessage, message,50 sendData, subject, successMessage, target, targets, validation, i, len;51 subject = sendemail.$subject.val();52 body = sendemail.$emailEditor.save().data;53 targets = [];54 sendemail.$send_to.filter(':checked').each(function() {55 return targets.push(this.value);56 });57 if (subject === '') {58 return alert(gettext('Your message must have a subject.')); // eslint-disable-line no-alert59 } else if (body === '') {60 return alert(gettext('Your message cannot be blank.')); // eslint-disable-line no-alert61 } else if (targets.length === 0) {62 return alert(gettext( // eslint-disable-line no-alert63 'Your message must have at least one target.'));64 } else {65 validation = KeywordValidator().validate_string(body);66 if (!validation.isValid) {67 message = gettext(68 'There are invalid keywords in your email. Check the following keywords and try again.');69 message += '\n' + validation.invalidKeywords.join('\n');70 alert(message); // eslint-disable-line no-alert71 return false;72 }73 displayTarget = function(value) {74 if (value === 'myself') {75 return gettext('Yourself');76 } else if (value === 'staff') {77 return gettext('Everyone who has staff privileges in this course');78 } else if (value === 'learners') {79 return gettext('All learners who are enrolled in this course');80 } else if (value.startsWith('cohort')) {81 return gettext('All learners in the {cohort_name} cohort')82 .replace('{cohort_name}', value.slice(value.indexOf(':') + 1));83 } else if (value.startsWith('track')) {84 return gettext('All learners in the {track_name} track')85 .replace('{track_name}', value.slice(value.indexOf(':') + 1));86 }87 };88 successMessage = gettext('Your email message was successfully queued for sending. In courses with a large number of learners, email messages to learners might take up to an hour to be sent.'); // eslint-disable-line max-len89 confirmMessage = gettext(90 'You are sending an email message with the subject {subject} to the following recipients.');91 for (i = 0, len = targets.length; i < len; i++) {92 target = targets[i];93 confirmMessage += '\n-' + displayTarget(target);94 }95 confirmMessage += '\n\n' + gettext('Is this OK?');96 fullConfirmMessage = confirmMessage.replace('{subject}', subject);97 if (confirm(fullConfirmMessage)) { // eslint-disable-line no-alert98 sendData = {99 action: 'send',100 send_to: JSON.stringify(targets),101 subject: subject,102 message: body103 };104 return $.ajax({105 type: 'POST',106 dataType: 'json',107 url: sendemail.$btn_send.data('endpoint'),108 data: sendData,109 success: function() {110 return sendemail.display_response(successMessage);111 },112 error: statusAjaxError(function() {113 return sendemail.fail_with_error(gettext('Error sending email.'));114 })115 });116 } else {117 sendemail.task_response.empty();118 return sendemail.$request_response_error.empty();119 }120 }121 });122 this.$btn_task_history_email.click(function() {123 var url = sendemail.$btn_task_history_email.data('endpoint');124 return $.ajax({125 type: 'POST',126 dataType: 'json',127 url: url,128 success: function(data) {129 if (data.tasks.length) {130 return createTaskListTable(sendemail.$table_task_history_email, data.tasks);131 } else {132 sendemail.$history_request_response_error.text(133 gettext('There is no email history for this course.')134 );135 return sendemail.$history_request_response_error.css({136 display: 'block'137 });138 }139 },140 error: statusAjaxError(function() {141 return sendemail.$history_request_response_error.text(142 gettext('There was an error obtaining email task history for this course.')143 );144 })145 });146 });147 this.$btn_task_history_email_content.click(function() {148 var url = sendemail.$btn_task_history_email_content.data('endpoint');149 return $.ajax({150 type: 'POST',151 dataType: 'json',152 url: url,153 success: function(data) {154 if (data.emails.length) {155 createEmailContentTable(sendemail.$table_email_content_history,156 sendemail.$email_content_table_inner, data.emails157 );158 return createEmailMessageViews(sendemail.$email_messages_wrapper, data.emails);159 } else {160 sendemail.$content_request_response_error.text(161 gettext('There is no email history for this course.')162 );163 return sendemail.$content_request_response_error.css({164 display: 'block'165 });166 }167 },168 error: statusAjaxError(function() {169 return sendemail.$content_request_response_error.text(170 gettext('There was an error obtaining email content history for this course.')171 );172 })173 });174 });175 this.$send_to.change(function() {176 var targets;177 var inputDisable = function() {178 this.checked = false;179 this.disabled = true;180 return true;181 };182 var inputEnable = function() {183 this.disabled = false;184 return true;185 };186 if ($('input#target_learners:checked').length) {187 sendemail.$cohort_targets.each(inputDisable);188 sendemail.$course_mode_targets.each(inputDisable);189 } else {190 sendemail.$cohort_targets.each(inputEnable);191 sendemail.$course_mode_targets.each(inputEnable);192 }193 targets = [];194 $('input[name="send_to"]:checked+label').each(function() {195 return targets.push(this.innerText.replace(/\s*\n.*/g, ''));196 });197 return $('.send_to_list').text(gettext('Send to:') + ' ' + targets.join(', '));198 });199 }200 SendEmail.prototype.fail_with_error = function(msg) {201 this.$task_response.empty();202 this.$request_response_error.empty();203 this.$request_response_error.text(msg);204 return $('.msg-confirm').css({205 display: 'none'206 });207 };208 SendEmail.prototype.display_response = function(dataFromServer) {209 this.$task_response.empty();210 this.$request_response_error.empty();211 this.$task_response.text(dataFromServer);212 return $('.msg-confirm').css({213 display: 'block'214 });215 };216 return SendEmail;217 }());218 this.Email = (function() {219 function email($section) {220 var eml = this;221 this.$section = $section;222 this.$section.data('wrapper', this);223 plantTimeout(0, function() {224 return new SendEmail(eml.$section.find('.send-email'));225 });226 this.instructor_tasks = new (PendingInstructorTasks())(this.$section);227 }228 email.prototype.onClickTitle = function() {229 return this.instructor_tasks.task_poller.start();230 };231 email.prototype.onExit = function() {232 return this.instructor_tasks.task_poller.stop();233 };234 return email;235 }());236 _.defaults(window, {237 InstructorDashboard: {}238 });239 _.defaults(window.InstructorDashboard, {240 sections: {}241 });242 _.defaults(window.InstructorDashboard.sections, {243 Email: this.Email244 });...
send-emails.test.js
Source:send-emails.test.js
1const env = require('../../env')2const mockContext = require('../../mock-context')3const mockMessage = require('../../mock-message')4const mockReference = require('../../mock-reference')5let sendEmail6let sendEmails7let emailAddresses8let defaultEmailAddresses9describe('send emails', () => {10 beforeEach(() => {11 jest.clearAllMocks()12 jest.resetModules()13 jest.mock('../../../ffc-pay-alerts/notify/send-email')14 sendEmail = require('../../../ffc-pay-alerts/notify/send-email')15 sendEmails = require('../../../ffc-pay-alerts/notify/send-emails')16 emailAddresses = ['test@test.com', 'not-real@test.com']17 defaultEmailAddresses = env.notifyEmailAddresses.split(',')18 jest.mock('uuid', () => ({ v4: () => mockReference }))19 })20 afterEach(() => {21 jest.clearAllMocks()22 })23 test('should call sendEmail when valid context, message, emailAddresses and reference are received', async () => {24 await sendEmails(mockContext, mockMessage, emailAddresses, mockReference)25 expect(sendEmail).toHaveBeenCalled()26 })27 test('should call sendEmail 2 times when 2 emailAddresses are received', async () => {28 await sendEmails(mockContext, mockMessage, emailAddresses, mockReference)29 expect(sendEmail).toHaveBeenCalledTimes(2)30 })31 test('should call sendEmail with context, message, reference and each emailAddress when valid context, message, emailAddresses and reference are received', async () => {32 await sendEmails(mockContext, mockMessage, emailAddresses, mockReference)33 expect(sendEmail.mock.calls[0]).toEqual([mockContext, mockMessage, emailAddresses[0], mockReference])34 expect(sendEmail.mock.calls[1]).toEqual([mockContext, mockMessage, emailAddresses[1], mockReference])35 })36 test('should call sendEmail 1 time when 1 string emailAddress is received', async () => {37 await sendEmails(mockContext, mockMessage, emailAddresses[0], mockReference)38 expect(sendEmail).toHaveBeenCalledTimes(1)39 })40 test('should call sendEmail with context, message, emailAddress and reference when 1 string emailAddress is received', async () => {41 await sendEmails(mockContext, mockMessage, emailAddresses[0], mockReference)42 expect(sendEmail).toHaveBeenCalledWith(mockContext, mockMessage, emailAddresses[0], mockReference)43 })44 test('should call sendEmail 1 time when 1 array emailAddress is received', async () => {45 await sendEmails(mockContext, mockMessage, [emailAddresses[0]], mockReference)46 expect(sendEmail).toHaveBeenCalledTimes(1)47 })48 test('should call sendEmail with context, message, emailAddress and reference when 1 array emailAddress is received', async () => {49 await sendEmails(mockContext, mockMessage, [emailAddresses[0]], mockReference)50 expect(sendEmail).toHaveBeenCalledWith(mockContext, mockMessage, emailAddresses[0], mockReference)51 })52 test('should call sendEmail with context, message and default emailAddresses and reference when valid context and message are received', async () => {53 await sendEmails(mockContext, mockMessage)54 expect(sendEmail.mock.calls[0]).toEqual([mockContext, mockMessage, defaultEmailAddresses[0], mockReference])55 expect(sendEmail.mock.calls[1]).toEqual([mockContext, mockMessage, defaultEmailAddresses[1], mockReference])56 })57 test('should handle and resolve any thrown error from sendEmail', async () => {58 sendEmail.mockRejectedValue(new Error('Oh dear'))59 expect(sendEmails(mockContext, mockMessage)).resolves.not.toThrow()60 })61 test('confirm error thrown by sendEmail is caught and logged', async () => {62 const errorMock = new Error('Oh dear')63 const logSpy = jest.spyOn(mockContext, 'log')64 sendEmail.mockRejectedValue(errorMock)65 await sendEmails(mockContext, mockMessage)66 expect(logSpy).toHaveBeenCalledWith(errorMock)67 })...
Using AI Code Generation
1const qawolf = require("qawolf");2(async () => {3 const browser = await qawolf.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await qawolf.register(page);7 await page.click("#identifierId");8 await page.fill("#identifierId", "
Using AI Code Generation
1const qawolf = require("qawolf");2const browser = await qawolf.launch();3const context = await browser.newContext();4const page = await context.newPage();5await qawolf.register(page);6await page.click("input[name=q]");7await page.fill("input[name=q]", "Hello");8await page.press("input[name=q]", "Enter");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!