From d1f2c01db52c8f9cd2bc1095a0214d06acbd3bb3 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 27 Jul 2017 17:20:02 -0700 Subject: [PATCH] Attempt to fix tests to not throw targetClosed exception The exception happens due to some of the tests initiating operation and not waiting for the operation to finish. --- test/test.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/test.js b/test/test.js index ca2aad39..80b2bf5d 100644 --- a/test/test.js +++ b/test/test.js @@ -733,17 +733,17 @@ describe('Puppeteer', function() { }); describe('Page.Events.PageError', function() { - it('should fire', function(done) { - page.on('pageerror', error => { - expect(error.message).toContain('Fancy'); - done(); - }); + it('should fire', SX(async function() { + let error = null; + page.once('pageerror', e => error = e); page.navigate(PREFIX + '/error.html'); - }); + await waitForEvents(page, 'pageerror'); + expect(error.message).toContain('Fancy'); + })); }); describe('Page.Events.Request', function() { - it('should fire', SX(async function(done) { + it('should fire', SX(async function() { let requests = []; page.on('request', request => requests.push(request)); await page.navigate(EMPTY_PAGE); @@ -882,17 +882,16 @@ describe('Puppeteer', function() { it('should move with the arrow keys', SX(async function(){ await page.navigate(PREFIX + '/input/textarea.html'); await page.focus('textarea'); - let keyboard = page.keyboard; await page.type('Hello World!'); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!'); for (let i = 0; i < 'World!'.length; i++) page.press('ArrowLeft'); await page.type('inserted '); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello inserted World!'); - keyboard.down('Shift'); + page.keyboard.down('Shift'); for (let i = 0; i < 'inserted '.length; i++) page.press('ArrowLeft'); - keyboard.up('Shift'); + page.keyboard.up('Shift'); await page.press('Backspace'); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!'); })); @@ -991,12 +990,12 @@ describe('Puppeteer', function() { it('keyboard.modifiers()', SX(async function(){ let keyboard = page.keyboard; expect(keyboard._modifiers).toBe(0); - keyboard.down('Shift'); + await keyboard.down('Shift'); expect(keyboard._modifiers).toBe(8); - keyboard.down('Alt'); + await keyboard.down('Alt'); expect(keyboard._modifiers).toBe(9); - keyboard.up('Shift'); - keyboard.up('Alt'); + await keyboard.up('Shift'); + await keyboard.up('Alt'); expect(keyboard._modifiers).toBe(0); })); it('should resize the textarea', SX(async function(){