I'm using create-react-app-typescript and want to create a function that will be available in every test file similar to jest's globals.
Is it possible to write a function in the src/setupTest.ts
file that will be available in every test file?
I want to write a react-intl
helper that I can use when testing components. I have the following code:
// src/setupTests.ts
import { createIntlWrapper } from 'test-utils/react/react-intl';
import enMessages from './assets/locales/en.json';
const wrapIntl = createIntlWrapper('en', enMessages);
The createIntlWrapper
returns a function which mimic this helper function.
When I need to test components that have react-intl components, I want to be able to wrap the JSX with wrapIntl(<SampleComponent />)
without importing the code above in every file.
global.wrapIntl = createIntlWrapper('en', enMessages);
it's the node's equivalent to window.someGlobalVariable = 'something'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With