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

Loading dirty-chai before chai-jquery breaks empty() #11

Closed
justin-lau opened this issue Oct 4, 2015 · 3 comments
Closed

Loading dirty-chai before chai-jquery breaks empty() #11

justin-lau opened this issue Oct 4, 2015 · 3 comments

Comments

@justin-lau
Copy link

The readme stated that dirty-chai should be loaded before any other plugins, but I found that if I load dirty-chai before chai-jquery, a should.be.empty() throws a TypeError: empty is not a function.

However, if I load chai-jquery before dirty-chai, the said problem is gone, and what's more, the property assertions in chai-jquery actually convert to method assertions.

@astorije
Copy link
Contributor

astorije commented May 3, 2016

FWIW, while using the chai-immutable plugin, @iensu noticed the similar requirement: astorije/chai-immutable#57.

@joshperry
Copy link
Contributor

Sorry guys, dirty-chai does hook the internal methods that plugins use to extend chai in order to convert assertions to methods. I do have an outstanding PR with tests that work a problem with a similar issue to this. Perhaps the guidance should just be changed to run dirty-chai last instead of first.

Hopefully this will get less hairy with extendable assertion formats that are supposed to come in a newer chai. I'll be tracking this in #7.

@adamcohen
Copy link

adamcohen commented May 16, 2018

I'm running into the same issue with chai-fs, although I can't fix the TypeError: expect(...).to.be.empty is not a function error regardless of the order.

I've tried every permutation of the following lines, but nothing works:

const chaiFS = require('chai-fs')
const dirtyChai = require('dirty-chai')

chai.use(dirtyChai)
chai.use(chaiFS)

It seems that once you use chai.use(chaiFS) in one of your tests, any other test that uses to.be.empty() will fail.

I've gotten around this by using the property form of empty instead of the function form, and just disabling the eslint rule wherever I do this, but it's far from ideal:

// eslint-disable-next-line no-unused-expressions
 expect(subject).to.be.empty

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

4 participants