test: do not leave dangling listener on shared browser object (#1674)

This resulted in quite a few failures on travis.
This commit is contained in:
Andrey Lushnikov 2017-12-27 19:38:33 -07:00 committed by GitHub
parent e7bcc05554
commit 02720e4f22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3348,9 +3348,9 @@ describe('Page', function() {
expect((await changedTarget).url()).toBe(server.EMPTY_PAGE); expect((await changedTarget).url()).toBe(server.EMPTY_PAGE);
}); });
it('should not report uninitialized pages', async({page, server, browser}) => { it('should not report uninitialized pages', async({page, server, browser}) => {
browser.on('targetchanged', () => { let targetChanged = false;
expect(false).toBe(true, 'target should not be reported as changed'); const listener = () => targetChanged = true;
}); browser.on('targetchanged', listener);
const targetPromise = new Promise(fulfill => browser.once('targetcreated', target => fulfill(target))); const targetPromise = new Promise(fulfill => browser.once('targetcreated', target => fulfill(target)));
const newPagePromise = browser.newPage(); const newPagePromise = browser.newPage();
const target = await targetPromise; const target = await targetPromise;
@ -3363,6 +3363,8 @@ describe('Page', function() {
expect(target2.url()).toBe('about:blank'); expect(target2.url()).toBe('about:blank');
await evaluatePromise; await evaluatePromise;
await newPage.close(); await newPage.close();
expect(targetChanged).toBe(false, 'target should not be reported as changed');
browser.removeListener('targetchanged', listener);
}); });
it('should not crash while redirecting if original request was missed', async({page, server, browser}) => { it('should not crash while redirecting if original request was missed', async({page, server, browser}) => {
let serverResponse = null; let serverResponse = null;