jest-puppeteer
jest-puppeteer copied to clipboard
expect doesn't await for page.title()
trafficstars
🐛 Bug Report
Trying to assert with expect and resolve doesn't await for promise and results in early termination of script resulting in Error: Navigation failed because browser has disconnected!
To Reproduce
dependencies:
"dependencies": {
"expect-puppeteer": "^4.1.1",
"jest": "^24.8.0",
"jest-puppeteer": "^4.2.0",
"mkdirp": "^0.5.1",
"puppeteer": "^1.18.1"
},
"devDependencies": {
"jest-junit": "^6.4.0"
}
describe('Single Property', () => {
beforeAll(async () => {
await page.setViewport({width: 1366, height: 768});
await page.goto('http://localhost:3000');
await page.waitForNavigation({waitUntil: 'networkidle0'});
});
it('should be titled "Google"', async () => {
await expect(page.title()).resolves.toMatch('Google');
});
});
Expected behavior
Should not crash with error.
## System:
- OS: Windows 10
- CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
- Memory: 9.28 GB / 15.88 GB
## Binaries:
- Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
- npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
@gregberge Hi, what if you add page.title() into variable and not into expect itself?
beforeAll(async () => {
await page.setViewport({width: 1366, height: 768});
await page.goto('http://localhost:3000');
await page.waitForNavigation({waitUntil: 'networkidle0'});
const title = await page.title();
});
it('should be titled "Google"', async () => {
await expect(title).resolves.toMatch('Google');
});
});```
Don't know if it is still relevant in latest version, I close it. Feel free to open a new issue if you experience this problem.