11

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?

skyboyer
  • 15,149
  • 4
  • 41
  • 56
Stefan
  • 1,360
  • 3
  • 12
  • 32

1 Answers1

0

As you say i agree that the problem is the async sequentially, as explained in that github bugreport in Patrick Hulce answer:

FWIW I also ran into this and was led to this issue. Only happened in CI when an async test timed out but the underlying action continued until after the test suite finished (and I'm guessing the callback tried to add the result of the expectation). I could never get it to happen locally though.

so probably your error is inside "//my test steps" where you manipulate something in both the test that you can/need manipulate before running the async process.

Legion
  • 744
  • 6
  • 22