-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support setup via jest.config.js #22
Comments
bump on this |
Bump |
I got something working based on https://github.com/jest-community/jest-extended/blob/2bd088758d08a5ada82f28d26757f1d7f4ccaca4/src/all/index.js. Getting it to play nicely with my other VS Code extensions, XO, etc. was a bit of a pain. Here's where I'm using it in a project: https://github.com/Antyos/image-layout/tree/adf3b4acde4482390d2e006db802a2c9eb7e965c. // ./jest.config.ts
module.exports = {
setupFilesAfterEnv: [
'jest.config.ts',
// ...
],
} // ./jest.setup.ts
import { toMatchCloseTo, toBeDeepCloseTo } from 'jest-matcher-deep-close-to';
// Patch `toMatchCloseTo` and `toBeDeepCloseTo` into jest's expect()
interface MaybeHasJestExpect {
expect?: jest.Expect;
}
// Based on: https://github.com/jest-community/jest-extended/blob/2bd088758d08a5ada82f28d26757f1d7f4ccaca4/src/all/index.js
const jestExpect = (global as unknown as MaybeHasJestExpect).expect;
if (jestExpect === undefined) {
throw new Error(
"Unable to find Jest's global expect. " +
'Please check you have added jest-extended correctly to your jest configuration. ' +
'See https://github.com/jest-community/jest-extended#setup for help.',
);
}
jestExpect.extend({ toMatchCloseTo, toBeDeepCloseTo }); // ./src/global.d.ts
export * from 'jest-matcher-deep-close-to'; In my {
// ...
// Comment out the following line
"exclude": ["src/**/*.test.*"],
} |
To avoid having to add this boilerplate to each test file that uses the library:
the
expect.extend
line could instead be added at the bottom ofindex.js
in which case the expectations can be made globally available in a user'sjest.config.js
with something like:I'd make a PR for this but I'm not set up for hacking on typescript code and this itch isn't annoying enough.
The text was updated successfully, but these errors were encountered: