Created
November 2, 2016 17:07
-
-
Save 0xR/9232db946e3198ef619168a33a92232d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure chai and jasmine ".not" play nice together | |
const originalNot = Object.getOwnPropertyDescriptor(chai.Assertion.prototype, 'not').get; | |
Object.defineProperty(chai.Assertion.prototype, 'not', { | |
get() { | |
Object.assign(this, this.assignedNot); | |
return originalNot.apply(this); | |
}, | |
set(newNot) { | |
this.assignedNot = newNot; | |
return newNot; | |
}, | |
}); | |
// Combine both jest and chai matchers on expect | |
const originalExpect = global.expect; | |
global.expect = (actual) => { | |
const originalMatchers = originalExpect(actual); | |
const chaiMatchers = chai.expect(actual); | |
const combinedMatchers = Object.assign(chaiMatchers, originalMatchers); | |
return combinedMatchers; | |
}; |
This appears to work alright for me now with jest 26.6.3 and chai 4.3.0. It even works after mixing in chai-as-promised, chai-string and chai-datetime!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@JaKXz nice catch! Did you end up working something out with chai v4?