chai-jquery
chai-jquery copied to clipboard
Add ability to specify jQuery object
At the moment chai-jquery assumes jQuery is jQuery on the window object, but this isn't always the case, e.g. Ember has Ember.$. Allow an option to specify the jQuery object.
I'm dealing with a similar issue: multiple jQuery instances. How about replacing this:
if (obj instanceof $) { /* ... */ }
to this:
if ('jquery' in Object(obj)) { /* ... */ }
Based on this SO answer. Duck test instead of instance test.
Should probably be 'jQuery', no?
Nope. It's just a property where jQuery provides version:
> 'jquery' in Object($("body"))
true
> $("body").jquery
"1.11.0"
Ah, make sense. Always forget that's how you get the version, kinda off putting.
Related to this issue, I was thinking of using chai-jquery with zombie.js. Jquery is available from browser.window.$. Now I have to write following after each page load, since browser.window.$ will be new after each page load:
before(function () {
chai.use(function (chai, utils) {
return chaiJquery(chai, utils, browser.window.$)
})
})
What if users could implement a function that is called for every assertion:
chai.use(function (chai, utils) {
return chaiJquery(chai, utils, function() { return browser.window.$})
})
Would really love to see this. I'm in a similar situation where the hard coded instanceof check is really problematic. I have multiple versions of jQuery and have to do some crazy juggling to make this work.
I made a pull request https://github.com/chaijs/chai-jquery/pull/66
This pull request would fix my issue, any reason why it can't move ahead?
+1