IjzerenHein / firestorter

Use Google Firestore in React with zero effort, using MobX 🤘
http://firestorter.com
MIT License
378 stars 50 forks source link

Aysnc Timeout running `npm test` #48

Closed imikemiller closed 5 years ago

imikemiller commented 5 years ago

I am getting this error when running the tests. I have a fix- I just chucked a call to done() at the end of the offending test case - but this feels pretty arbitrary. Seems like a call to done() should be included in each async test in case, for some reason, firestore is slow to respond and one of the tests ends up over running timeout

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      29 | });
      30 | 
    > 31 | test('ready', async () => {
         | ^
      32 |  expect.assertions(3);
      33 |  const doc = new Document('artists/FooFighters');
      34 |  doc.fetch();

      at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20)
      at Object.test (test/Document.snapshot.test.js:15:1)
imikemiller commented 5 years ago

The fix for clarity:


test('ready', async (done) => {
    expect.assertions(3);
    const doc = new Document('artists/FooFighters');
    doc.fetch();
    expect(doc.isLoading).toBe(true);
    await doc.ready();
    expect(doc.isLoading).toBe(false);
    expect(doc.data.topAlbumId).toBe('TheColourAndTheShape');
    done(); // such a valuable contribution i know!!
});
imikemiller commented 5 years ago

OK ignore me, the error is intermittent and is probably my connection. I did some further tests by forcing a delay inside some test cases (await new Promise(resolve => setTimeout(resolve, 5000));) and there error is thrown regardless of whether done() is called or not (this is obvious in hindsight).