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

Add ability to specify jQuery object #36

Open
knownasilya opened this issue Jan 21, 2014 · 9 comments
Open

Add ability to specify jQuery object #36

knownasilya opened this issue Jan 21, 2014 · 9 comments

Comments

@knownasilya
Copy link

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.

@tadas-s
Copy link

tadas-s commented Dec 23, 2014

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.

@knownasilya
Copy link
Author

Should probably be 'jQuery', no?

@tadas-s
Copy link

tadas-s commented Dec 23, 2014

Nope. It's just a property where jQuery provides version:

> 'jquery' in Object($("body"))
true
> $("body").jquery
"1.11.0"

@knownasilya
Copy link
Author

Ah, make sense. Always forget that's how you get the version, kinda off putting.

@eeroan
Copy link

eeroan commented Mar 18, 2015

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.$})
})

@brian-mann
Copy link

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.

@eeroan
Copy link

eeroan commented Apr 21, 2015

I made a pull request #66

@brian-mann
Copy link

This pull request would fix my issue, any reason why it can't move ahead?

@jgerigmeyer
Copy link

+1

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

5 participants