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

chai-fs impacts promise handling when loaded after chai-as-promised #218

Open
deployable opened this issue Sep 12, 2017 · 2 comments
Open

Comments

@deployable
Copy link

deployable commented Sep 12, 2017

When using both chai-fs and chai-as-promised, promises start returning before being handled, kind of like when you run an async test without done.

I'm not sure which side the issues sits with so have raised it on both

Example test:

const chai = require('chai')
const expect = chai.expect
chai.should()
chai.use(require('chai-as-promised'))
chai.use(require('chai-fs'))

describe('resolve', function(){

  it('expect', function(){
    return expect( Promise.resolve('two') ).to.eventually.equal('one')
  })

  it('should', function(){
    return Promise.resolve('two').should.eventually.equal('one')
  })

})       

Results in promises being rejected but not handled by mocha:

○ → mocha

  resolve
    ✓ shouldn't resolve
(node:79302) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected 'two' to equal 'one'
    ✓ shouldn't resolve
(node:79302) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): AssertionError: expected 'two' to equal 'one'


  2 passing (16ms)

Swapping the order and loading chai-fs first:

chai.use(require('chai-fs'))
chai.use(require('chai-as-promised'))

Results in the normal promise handling behaviour:

○ → mocha

  resolve
    1) expect
    2) should


  0 passing (16ms)
  2 failing

  1) resolve expect:

      AssertionError: expected 'two' to equal 'one'
      + expected - actual

      -two
      +one
      
      at getBasePromise.then.then.newArgs (node_modules/chai-as-promised/lib/chai-as-promised.js:302:22)

  2) resolve should:

      AssertionError: expected 'two' to equal 'one'
      + expected - actual

      -two
      +one
      
      at getBasePromise.then.then.newArgs (node_modules/chai-as-promised/lib/chai-as-promised.js:302:22)
@deployable
Copy link
Author

chaijs/chai-fs#38

@BadIdeaException
Copy link

Sorry to necromance, but having run into this exact same issue today, I think the caveat about needing to be chai.used last should be made way more prominent in the readme. As it is, it's kind of hidden far down, and easy to miss.

Love this package! I use it on pretty much all of my projects.

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

2 participants