debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

using with chai assert #13

Closed cassus closed 8 years ago

cassus commented 8 years ago

I'd like to use assert.containSubset or something similar using the assert chai interface and not the should or expect.

I found this workaround.

chai.assert.containSubset = function(val, exp, msg) {
    new chai.Assertion(val, msg).to.be.containSubset(exp);
}
eagleeye commented 8 years ago

Hi, @cassus! Unfortunately, I can't find any good examples, where chai.assert is extended with new functionality. As far I get from the source code of chai - assert interface works a bit different from should/expect and as for now I can't suggest something better rather that workaround you are using. In case if you use some chai plugins that allows you to extend chai.assert please let me know.

cassus commented 8 years ago

I made this workaround based on https://github.com/michelsalib/chai-shallow-deep-equal/blob/master/chai-shallow-deep-equal.js#L97 where it's part of the library.

Chai-immutable also uses similar pattern to add to the chai.assert object: https://github.com/astorije/chai-immutable/blob/master/chai-immutable.js#L482

eagleeye commented 8 years ago

okay, then I agree that this could be added. Will do that soon

eagleeye commented 8 years ago

PR #14