Skip to content

Instantly share code, notes, and snippets.

@0xR
Created November 2, 2016 17:07
Show Gist options
  • Save 0xR/9232db946e3198ef619168a33a92232d to your computer and use it in GitHub Desktop.
Save 0xR/9232db946e3198ef619168a33a92232d to your computer and use it in GitHub Desktop.
// 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;
};
@nrako
Copy link

nrako commented Jun 29, 2017

@JaKXz nice catch! Did you end up working something out with chai v4?

@siddharthvp
Copy link

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