Skip to content

Commit eff13ca

Browse files
committed
fix: invalid chai property error when chai is added globally
1 parent c4f7aea commit eff13ca

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/assertThat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const assertThat = (...args) => {
4141
} else {
4242
if (global && global.expect) {
4343
const expectation = global.expect();
44-
if (expectation && expectation.nothing) {
44+
if (expectation && 'nothing' in expectation) {
4545
expectation.nothing();
4646
}
4747
}

test/node/assertThatSpec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,18 @@ describe('assertThat', () => {
114114

115115
assert.equal(expectNothingWasCalled, true);
116116
});
117+
118+
it('should not throw when nothing is not available on expect (fix "Invalid Chai property" in vitest)', () => {
119+
const chaiFake = {irrelevant: 'property'};
120+
121+
global.expect = () => new Proxy(chaiFake, {
122+
get(target, property) {
123+
if (!Object.keys(target).includes(property)) {
124+
throw Error(`Invalid Chai property: ${property}`);
125+
}
126+
}
127+
});
128+
129+
__.assertThat(true, __.is(__.equalTo(true)));
130+
});
117131
});

0 commit comments

Comments
 (0)