Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

### Fixes

- `[expect]` Make expect extension properties `configurable` ([#11978](https://github.com/facebook/jest/pull/11978))

### Chore & Maintenance

- `[jest-config, jest-util]` Use `ci-info` instead of `is-ci` to detect CI environment ([11973](https://github.com/facebook/jest/pull/11973))
- `[jest-config, jest-util]` Use `ci-info` instead of `is-ci` to detect CI environment ([#11973](https://github.com/facebook/jest/pull/11973))

### Performance

## 27.3.0

### Features

- `[jest-config]` Add `testEnvironmentOptions.html` to apply to jsdom input ([11950](https://github.com/facebook/jest/pull/11950))
- `[jest-config]` Add `testEnvironmentOptions.html` to apply to jsdom input ([#11950](https://github.com/facebook/jest/pull/11950))
- `[jest-resolver]` Support default export (`.`) in `exports` field _if_ `main` is missing ([#11919](https://github.com/facebook/jest/pull/11919))

### Fixes
Expand Down
18 changes: 18 additions & 0 deletions packages/expect/src/__tests__/extend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,21 @@ it('prints the Symbol into the error message', () => {
}),
).toThrowErrorMatchingSnapshot();
});

it('allows overriding existing extension', () => {
jestExpect.extend({
toAllowOverridingExistingMatcher(_expected: unknown) {
return {pass: _expected === 'bar'};
},
});

jestExpect('foo').not.toAllowOverridingExistingMatcher();

jestExpect.extend({
toAllowOverridingExistingMatcher(_expected: unknown) {
return {pass: _expected === 'foo'};
},
});

jestExpect('foo').toAllowOverridingExistingMatcher();
});
6 changes: 6 additions & 0 deletions packages/expect/src/jestMatchersObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ export const setMatchers = <State extends MatcherState = MatcherState>(
}

Object.defineProperty(expect, key, {
configurable: true,
enumerable: true,
value: (...sample: [unknown, ...Array<unknown>]) =>
new CustomMatcher(false, ...sample),
writable: true,
});
Object.defineProperty(expect.not, key, {
configurable: true,
enumerable: true,
value: (...sample: [unknown, ...Array<unknown>]) =>
new CustomMatcher(true, ...sample),
writable: true,
});
}
});
Expand Down