Jest: "done" should fail when called multiple times

Created on 26 Sep 2018  路  8Comments  路  Source: facebook/jest

I did some online searching and didn't find any discussion, so let me know if this is as expected. Happy to do a PR if this should be correct behavior

馃悰 Bug Report

Calling done() multiple times in one test should be a failure, but it succeeds

To Reproduce

it('should fail when done called second time', done => {
  done();
  done();
});

Expected behavior

Test fails with "done" called multiple times or some such message

Link to repl or repo (highly encouraged)

Above code snippet showcases issue. Looks like following test could be added to e2e failures:

test('done();done()', done => {
  done();
  done();
});

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
  Binaries:
    Node: 10.3.0 - /usr/local/bin/node
    Yarn: 1.5.1 - /usr/local/bin/yarn
    npm: 6.1.0 - /usr/local/bin/npm
Feature Request Help Wanted

Most helpful comment

Hello, me and another student are trying to fix this issue for a course in college. However, it's our first time working with jest so we are not so sure which files to run to reproduce this issue... Can you please replicate it in repl.it?

All 8 comments

I agree this should fail. Wanna send a PR for it? 馃榾

Hey, I'd like to take this up. Don't have enough context as it is though. From what I understand, this will have to be updated in both circus and jasmine(Env.js?). Could you give me a place to start?

The code for circus looks like something I can work with. The one for jasmine I don't quite grok. I don't see where the callback is provided. Basically what I plan on doing is to wrap done in a higher order function which increments a variable for done being called more than once. If it's called more than once then we mark the test as a fail.

Hello, me and another student are trying to fix this issue for a course in college. However, it's our first time working with jest so we are not so sure which files to run to reproduce this issue... Can you please replicate it in repl.it?

Hey @jmcsilva98, really happy to hear that!

Here's a repl.it, if you run this then the test passes but the OP requests that we fail it. The message could be something like "Expected done to be called once but it was called multiple times"

Here is a good place to start looking to add the feature. Note that this is the jest-circus runner so you should follow these instructions to run

Finally, here are some instructions on how to setup jest locally as well. These docs aren't our best, so if you have any questions, feel free to reach out to me on twitter or the reactiflux discord and I'd be happy to help!

May I give this a shot?

That would be great, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kgowru picture kgowru  路  3Comments

stephenlautier picture stephenlautier  路  3Comments

mmcgahan picture mmcgahan  路  3Comments

samzhang111 picture samzhang111  路  3Comments

Secretmapper picture Secretmapper  路  3Comments