Open bkimminich opened 6 years ago
To clarify what I'd actually want to achieve, here's an example:
xit('should contain the "key_type" property for backward compatibility with CTFd <1.1.0', function () {
return expect(generateData(challenges, options.noTextHints, options.noHintUrls, '')).to.eventually.deep.containSubset(
{
flagKeys: {
results: [
{ key_type: 'static' }
]
}
})
})
In the original test above I could then remove the key_type
property from the expectation and have functional and backward compatibility test separated.
I pushed what I would like to have in the end to develop
. I hope that helps understand my goal: https://github.com/bkimminich/juice-shop-ctf/blob/develop/test/unit/generateData-spec.js#L37-L76
I would also like to combine the two.
Right now, I am getting an error saying that containSubset
does not exist on PromisseAssertion :(
myPromise
.should.be.rejected
.and.should.eventually.to.containSubset([{
property1: {
property2: `some value`
}
}]);
I get this error only from typescript. At runtime, the code works
@IonelLupu @bkimminich The way chai-as-promised
works is gnarly. Are you using chai-subset
before or after chai-as-promised
? If you use chai-as-promise
after chai-subset
you should be able to .eventually
any of its assertions.
chai-as-promised
scans and wraps all of the language chains that are available at the time it is used, so the ones from chai-subset
don't get wrapped unless you use chai-subset
first.
This is kind of a footnote in the chai-as-promised
docs:
Note when using other Chai plugins: Chai as Promised finds all currently-registered asserters and promisifies them, at the time it is installed. Thus, you should install Chai as Promised last, after any other Chai plugins, if you expect their asserters to be promisified.
I hope to be able to replace some ugly
assertions (which need to specify all the object properties that I don't even care about) with
checks. Unfortunately that does not work, because that
eventually
-thing is a promise with the actual compare value nested inside. This gives me errors like:Using
to.eventually.deep.containSubset
does not work either. You can find the original unit test here: https://github.com/bkimminich/juice-shop-ctf/blob/develop/test/unit/generateData-spec.js#L37-L76Thanks in advance for your help/hints! Btw, merry :christmas_tree: to you!