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 #38

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

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

@vieiralucas
Copy link
Member

vieiralucas commented Nov 4, 2017

Hello @deployable, thanks for your issue

I believe that this is happening because chai-fs overwrites the equal assertion again (after chai-as-promised) making it no longer return a "thenable" so mocha can wait on it.

It is documented at chai-as-promised readme that you should load it last because of things like that.

from chai-as-promised readme

Note when using other Chai plugins: Chai as Promised finds all currently-registered asserters and promisifies them, at the time it is installed. Thus, you should install Chai as Promised last, after any other Chai plugins, if you expect their asserters to be promisified.

Basically the solution is to (as you have already pointed) load chai-as-promised last.

BadIdeaException added a commit to quartersbrief/quartersbrief that referenced this issue Nov 4, 2022
BadIdeaException added a commit to quartersbrief/quartersbrief that referenced this issue Nov 5, 2022
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