mardi 19 février 2019

Simple example using done and setTimeout inside a mocha test not working as expected

I have a simple test with an assertion contained in a setTimeout function as follows:

  it('asserts after timeout', (done) => {
    setTimeout(() => {
      expect(1).to.be.equal(1);
      done();
    }, 500);
  });

However I'm getting the following error:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Aucun commentaire:

Enregistrer un commentaire