Skip to content

setTimeout() after done() is called (--watch mode) #3014

Closed

Description

Hello, thanks for your work on this project.

The following test passes when calling mocha from cli, but the assertion throws after the test passes when adding the --watch flag.

Changing setTimeout to process.nextTick makes the test always pass in both modes.
Changing the delay on setTimeout to lower values (10ms) makes the test pass sometimes in watch mode.

What is the expected behaviour?

var assert = require('assert');

describe('Works consistently in regular cli and watch mode', function() {
  it('ignores setTimeout after done is called', function(done) {
    function myFunc(callback) {
      callback('sync');
      setTimeout(function() { callback('async'); }, 100);
    }

    myFunc(function(data) {
      assert.equal(data, 'sync');
      done();
    });
  });
});

Kind regards,

mocha 3.5.3
node 6.11.2
macOS 10.12.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    stalethis has been inactive for a while...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions