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

Does not work well with bluebird. #271

Open
mrdulin opened this issue Dec 28, 2020 · 0 comments
Open

Does not work well with bluebird. #271

mrdulin opened this issue Dec 28, 2020 · 0 comments

Comments

@mrdulin
Copy link

mrdulin commented Dec 28, 2020

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",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant