Closed anacronw closed 12 years ago
I'm closing - cannot reproduce in a difference instance so I'm guessing it was an environment error
It looks like you were using the chai-jquery plugin. Basically, the paradox you have here is that in order for chai-jquery to work, jquery must be in the global namespace. See this.
I had some setup code that tore it down temporarily with $.noConflict(true)
. Its true..that this is one difference between the two environments I tested on where one worked and the other threw an error.
I didn't realize chai-jquery was overriding the exist method which I thought belonged to chai. Oops! Perhaps that was exactly the issue there as you say. Is there a workaround to specifically test the non-existence of jQuery while using jquery-chai? Perhaps if I do something like:
chai.assert(undefined === jQuery)
Thanks in advance
I think what you are looking for is ...
window.should.not.have.property('jQuery');
But I'm not entirely sure what your trying to do. Note that if you are taking jQuery out of the global namespace you should not load the chai-jquery plugin. If you are using chai-jquery for something, you will need to use a separate file for your test checking for non-existence in the global namespace.
Hope that helps.
I have some library that injects jQuery as a dependency if its not there. I wanted to test this functionality in the specs, so I have to temporarily remove the jQuery namespace for that test.
Thanks! I will give that a try although I swear I tried that exactly line previously..didn't work the first time. Is there a subject to test in that line since should
and window.should
are equivalent?
when you load the should
interface you should be doing...
var should = chai.should();
If your not doing that, then that could cause problems as well. If you find that your unsure, switch to the expect
interface for a given test. You can mix and match if you wish.
expect(jQuery).to.not.exist;
Just for reference..
As I had thought window.should.not.have.property('jQuery')
returns with an error saying that you can't use property on undefined (since there is no subject in that statement).
chai.assert(undefined===jQuery)
worked for me, I'm sure the expect interface would actually have been an easier solution.
Thanks!
I am using Chai with Mocha in the browser and with the "should" BDD style. When I attempt to use
My test is the following:
I get the following error: