-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
docs: update expect.extend
examples
#13195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
const toBeWithinRange: MatcherFunction<[floor: number, ceiling: number]> = | ||
function (actual: unknown, floor: unknown, ceiling: unknown) { | ||
const toBeWithinRange: MatcherFunction<[floor: unknown, ceiling: unknown]> = | ||
function (actual, floor, ceiling) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaning up. I remember my thinking that expect.extend
could grab types from MatcherFunction
generics. Not sure if that was good idea. It involves lots of complexity (also in documentation), but has rather limited usage. For instance, does not work if expect
is not imported after calling expect.extend
. Fine for something small, but does not work with setupFilesAfterEnv
. Better to stick with the declaration – single solution which works in many situations.
To enable the matcher for all tests, move the `expect.extend` call to a [`setupFilesAfterEnv`](Configuration.md/#setupfilesafterenv-array) script: | ||
|
||
```js | ||
import {expect} from '@jest/globals'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it out. Jest will transpile setupFilesAfterEnv
scripts, so perhaps this can stay in ESM / TS for simplicity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! 😀
Happy about that! I had to do this some time ago. Well.. Better later than never ;D |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Currently the TypeScript examples of
expect.extend
usage are the only ones in documentation where@types/jest
is referenced. Elsewhere types imported from@jest/globals
are used. Perhaps it is time to update these last examples as well?The
@types/jest
related documentation will stay in old docs. Can be linked quickly if someone opens an issue. Also I am very interested to see DefinitelyTyped/DefinitelyTyped#62037 landing with Jest v30 release. Some work has to be done to make that happen, but in general where will be just one way to extend theMatchers
interface. And it this documented in this PR (;Test plan
Tried out both JS and TS examples locally.