Don't use expect within Promises (#5466) (#5473)

* Don't use expect within Promises (#5466)

If a call to expect fails within a Promise it will not
be resolved, and causing the test to crash.

The patch aligns the code similar to what is used by all
the other tests.
This commit is contained in:
Henrik Skupin 2020-05-26 10:22:11 +02:00 committed by GitHub
parent dfb2e6056b
commit 6cfe142af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14990 additions and 14977 deletions

5
src/protocol.d.ts vendored
View File

@ -1,5 +1,5 @@
// This is generated from /utils/protocol-types-generator/index.js // This is generated from /utils/protocol-types-generator/index.js
type binary = string; type binary = string;
declare module Protocol { declare module Protocol {
export module Accessibility { export module Accessibility {
@ -15498,5 +15498,6 @@ unsubscribes current runtime agent from Runtime.bindingCalled notifications.
"Runtime.removeBinding": Runtime.removeBindingReturnValue; "Runtime.removeBinding": Runtime.removeBindingReturnValue;
"Schema.getDomains": Schema.getDomainsReturnValue; "Schema.getDomains": Schema.getDomainsReturnValue;
} }
} }
export default Protocol; export default Protocol;

View File

@ -25,16 +25,22 @@ const {
describe('Page.Events.Dialog', function () { describe('Page.Events.Dialog', function () {
setupTestBrowserHooks(); setupTestBrowserHooks();
setupTestPageAndContextHooks(); setupTestPageAndContextHooks();
it('should fire', async () => { it('should fire', async () => {
const { page } = getTestState(); const { page } = getTestState();
page.on('dialog', (dialog) => { const onDialog = sinon.stub().callsFake((dialog) => {
dialog.accept();
});
page.on('dialog', onDialog);
await page.evaluate(() => alert('yo'));
expect(onDialog.callCount).toEqual(1);
const dialog = onDialog.firstCall.args[0];
expect(dialog.type()).toBe('alert'); expect(dialog.type()).toBe('alert');
expect(dialog.defaultValue()).toBe(''); expect(dialog.defaultValue()).toBe('');
expect(dialog.message()).toBe('yo'); expect(dialog.message()).toBe('yo');
dialog.accept();
});
await page.evaluate(() => alert('yo'));
}); });
itFailsFirefox('should allow accepting prompts', async () => { itFailsFirefox('should allow accepting prompts', async () => {

View File

@ -163,15 +163,21 @@ describe('navigation', function () {
// Make sure that network events do not emit 'undefined'. // Make sure that network events do not emit 'undefined'.
// @see https://crbug.com/750469 // @see https://crbug.com/750469
page.on('request', (request) => expect(request).toBeTruthy()); const requests = [];
page.on('requestfinished', (request) => expect(request).toBeTruthy()); page.on('request', (request) => requests.push('request'));
page.on('requestfailed', (request) => expect(request).toBeTruthy()); page.on('requestfinished', (request) => requests.push('requestfinished'));
page.on('requestfailed', (request) => requests.push('requestfailed'));
let error = null; let error = null;
await page await page
.goto(httpsServer.EMPTY_PAGE) .goto(httpsServer.EMPTY_PAGE)
.catch((error_) => (error = error_)); .catch((error_) => (error = error_));
if (isChrome) expect(error.message).toContain(EXPECTED_SSL_CERT_MESSAGE); if (isChrome) expect(error.message).toContain(EXPECTED_SSL_CERT_MESSAGE);
else expect(error.message).toContain('SSL_ERROR_UNKNOWN'); else expect(error.message).toContain('SSL_ERROR_UNKNOWN');
expect(requests.length).toBe(2);
expect(requests[0]).toBe('request');
expect(requests[1]).toBe('requestfailed');
}); });
itFailsFirefox( itFailsFirefox(
'should fail when navigating to bad SSL after redirects', 'should fail when navigating to bad SSL after redirects',