-
Notifications
You must be signed in to change notification settings - Fork 25
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
Compatible with chai-jquery? #16
Comments
I believe they overwrite each other because it gets nonsensical if You could fork one project and prefix it's assertions, though. A good regex search and replace or 2 could make that happen. |
@nathanboktae well, with a proper plugin design it would probably be possible to couple assertions to types, but that doesn't seem to be the case yet... @keithamus can you tell us if there is anything in the pipeline that would let these two plugin live next to each other? |
This isn't the first time we've seen this issue come up. In fact, we have an issue discussing how plugins can interface with chai, and each other, in a safe way; chaijs/chai#585. The issue is quite a read, but the TL;DR of it - for this scenario - is that assertions will be able to duck-type on the expected/actual values - and decide to pass on unknown values that don't pass the duck-typing. e.g.: // chai-jquery's version of .text() would be:
export default {
assertions: {
'text': {
'predicate': [ (actual) => actual instanceof $, (expected) => typeof expected === 'string' ],
'assert': (actual, expected) => actual.text() === expected
},
}
} // chai-dom's version of .text() would be:
export default {
assertions: {
'text': {
'predicate': [ (actual) => actual instanceof HTMLElement, (expected) => typeof expected === 'string' ],
'assert': (actual, expected) => actual.textContent === expected
},
}
} Neither plugin knows anything about the other plugins in play (or about chai actually) - but by specifying predicates can "opt-out" of asserting on Error: you wrote `expect({foo: 'bar'}).to.have.text('bar')` but no assertions can satisfy this.
The plugins: chai-dom and chai-jquery didn't understand expected value `{foo: 'bar'}` @nathanboktae I'd love it if you could comment on this issue (chaijs/chai#585) - we're looking for feedback from plugin maintainers to see if what we're doing is right, and hoping to get an active discussion going - so your feedback would be hugely useful! Constructive criticism fully welcome! |
BTW forgot to mention, thanks @Turbo87 for pinging me on this one! Always good to be bought in on issues like this so we in the chai team can see how the community is working. Speaking of which - I'm going to cc @lucasfcosta and @meeber; you don't need to comment here - but it's something to think on 😄 |
I'll close this issue as my question was answered. Thanks @nathanboktae and also thanks @keithamus for looking into this and taking care of Chai! |
Is it possible to use chai-jquery and chai-dom at the same time or do they overwrite each other?
The text was updated successfully, but these errors were encountered: