I've similarly struggled with this problem a number of times despite having @types/jest
in my devDependencies
too.
I created jest-without-globals
as a very tiny wrapper to support importing Jest's features instead of relying on globals, thereby ensuring the variables exist.
It's written in TypeScript as well, ensuring that it's typed properly when imported and that you don't need to do anything other than an import to make the types function.
Per the Usage docs, it's straightforward to use:
import { describe, it, expect } from 'jest-without-globals'
describe('describe should create a section', () => {
it('it should checkmark', () => {
expect('').toBe('')
})
})
All of the functions available in Jest's API, as well as jest
and expect
, can be imported from jest-without-globals
.