-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option
runBeforeUnloadOnClose
(#504)
* feat: add option runBeforeUnloadOnClose option that controls page.close({ runBeforeUnload: true }) * chore: add tests for runBeforeUnloadOnClose * chore(readme): document runBeforeUnloadOnClose * chore: rename test for runBeforeUnloadOnClose
- Loading branch information
Showing
3 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/jest-environment-puppeteer/tests/runBeforeUnloadOnClose.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe('runBeforeUnloadOnClose', () => { | ||
it('shouldn’t call page.close with runBeforeUnload by default', async () => { | ||
const closeSpy = jest.spyOn(page, 'close') | ||
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}`) | ||
await jestPuppeteer.resetPage() | ||
expect(closeSpy).toHaveBeenCalledTimes(1) | ||
expect(closeSpy).toHaveBeenCalledWith() | ||
}) | ||
|
||
it('should call page.close({ runBeforeUnload: true }) when runBeforeUnloadOnClose is set to true', async () => { | ||
const closeSpy = jest.spyOn(page, 'close') | ||
global.puppeteerConfig.runBeforeUnloadOnClose = true | ||
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}`) | ||
await jestPuppeteer.resetPage() | ||
expect(closeSpy).toHaveBeenCalledTimes(1) | ||
expect(closeSpy).toHaveBeenCalledWith({ runBeforeUnload: true }) | ||
}) | ||
}) |