I am using jest-puppeteer to run my webtests. If I am running my tests all defined in one file, everything works perfectly.
describe('user', () => {
jest.setTimeout(12000);
beforeEach(async () => {
await page.setViewport({width: 1200, height: 2000});
await page.goTo('http://localhost:3000');
});
it('test 1', async () => {
//my test steps
});
it('test 2', async () => {
//my test steps
});
});
However, if I am running each test in its own file, I get an error.
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined
FILE 1
describe('user', () => {
jest.setTimeout(12000);
beforeEach(async () => {
await page.setViewport({width: 1200, height: 2000});
await page.goTo('http://localhost:3000');
});
it('test 1', async () => {
//my test steps
});
});
FILE 2
describe('user', () => {
jest.setTimeout(12000);
beforeEach(async () => {
await page.setViewport({width: 1200, height: 2000});
await page.goTo('http://localhost:3000');
});
it('test 2', async () => {
//my test steps
});
});
Interestingly, if I add a console.log('some statement') as first step in test2, everything works again. That's why I think it might be a timing issue. I am running my tests sequentially, i.e. jest --runInBand
Can anyone help?