Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.slow() doesn't work in describe callbacks like this.timeout #2311

Closed
Macil opened this issue Jun 15, 2016 · 3 comments
Closed

this.slow() doesn't work in describe callbacks like this.timeout #2311

Macil opened this issue Jun 15, 2016 · 3 comments
Labels
type: bug a defect, confirmed by a maintainer

Comments

@Macil
Copy link

Macil commented Jun 15, 2016

describe('a', function() {
  this.timeout(5000);
  this.slow();

  it('1', function(cb) {
    setTimeout(cb, 3000);
  });

  it('2', function(cb) {
    this.slow(); // just for contrast with test 1
    setTimeout(cb, 3000);
  });
});

If I understand the docs correctly, I expect neither of the tests to timeout or have slow warnings because they're both covered by this.timeout and this.slow calls in the describe section. Neither of the tests timeout, but the first test (not covered by its own redundant this.slow) has a slow warning still:

  a
    ✓ 1 (3008ms)
    ✓ 2


  2 passing (6s)

mocha version 2.5.3

@boneskull
Copy link
Member

this.slow() doesn't do anything except return the current setting. You'll need to give it a parameter.

@Macil
Copy link
Author

Macil commented Jun 27, 2016

I'm confused because in test 2, calling this.slow() causes it to not show the slow warning without a parameter given. Removing it causes this output:

  a
    ✓ 1 (3006ms)
    ✓ 2 (3001ms)


  2 passing (6s)

@boneskull
Copy link
Member

OK, thanks. that's a bug. this is mostly for my benefit, but the explanation:

Runnable.prototype.slow = function(ms) {
  if (!arguments.length) {
    return this._slow;
  }
  if (typeof ms === 'string') {
    ms = milliseconds(ms);
  }
  debug('timeout %d', ms);
  this._slow = ms;
  return this;
};

When you call this.slow() from a test, it calls this:

Context.prototype.slow = function(ms) {
  this.runnable().slow(ms);
  return this;
}

If the latter function is called without a parameter, Runnable.prototype.slow() will have arguments equal to [undefined]. The fix is to test ms explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants