Skip to content

Commit

Permalink
Merge branch 'main' into kmclb-make-any-match-missing-primitive-wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Oct 19, 2021
2 parents 239f2e4 + 2e2b17a commit 52b5652
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

### Fixes

- `[expect]` Fix `.any()` checks on primitive wrapper classes ([11976](https://github.com/facebook/jest/pull/11976))
- `[expect]` Make `expect` extension properties `configurable` ([#11978](https://github.com/facebook/jest/pull/11978))
- `[expect]` Fix `.any()` checks on primitive wrapper classes ([#11976](https://github.com/facebook/jest/pull/11976))

### 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

0 comments on commit 52b5652

Please sign in to comment.