Skip to content

Does not work well with bluebird. #271

@mrdulin

Description

@mrdulin

Related issue: #169

chai-as-promised does not work with Promise.delay API of bluebird.

Mocha will give me timeout error:

  test
    1) should work


  0 passing (5s)
  1 failing

  1) test
       should work:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ldu020/workspace/github.com/mrdulin/expressjs-research/src/stackoverflow/35381245-todo/index.test.js)

Here is a minimal, reproducibe example:

const sinon = require('sinon');
// const Promise = require('bluebird');
// global.Promise = require('bluebird');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

chai.should();

Promise.delay = function (ms, value) {
  return new Promise((resolve) => setTimeout(() => resolve(value), ms));
};

describe('test', function () {
  var clock;

  beforeEach(function () {
    clock = sinon.useFakeTimers();
  });

  afterEach(function () {
    clock.restore();
  });

  it('should work', async function () {
    var promise = Promise.delay(10000, 'foo');
    clock.tick(10000);
    await promise.should.eventually.deep.equal('foo');
  });
});

If I create my own Promise.delay method with native promise, it works fine with chai-as-promised and sinon.useFakeTimers().

But, if I use the Promise.delay method of bluebird, it won't work. No matter whether you use const Promise = require('bluebird'); or global.Promise = require('bluebird');, both of them do not work

Environment information:

  • node: v10.16.2
  • "chai": "^4.2.0",
  • "chai-as-promised": "^7.1.1",
  • "mocha": "^8.2.1",
  • "sinon": "^8.1.1",
  • "bluebird": "^3.7.2",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions