The Jest documentation on Globals says the following (emphasis mine).
In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them. However, if you prefer explicit imports, you can do import {describe, expect, it} from '@jest/globals'.
So, why does typing jest
or npm test
with scripts.test
(in package.json
) pointing to jest --verbose
cause the ReferenceError: describe is not defined
error? Some of the questions around this on SO and elsewhere, mention that, jest
should be installed globally, installed with --save-dev
, referred to local node_modules
, etc. None of them work.
What am I missing?
This is my index.spec.js
.
function checkArgs(args) {
if (args.length > 4) {
// Error message on extraneous parameters
return false
} else if (args.length < 4) {
// Error message on insufficient parameters
return false
} else {
return true
}
}
describe("Arguments check", () => {
test("Number of arguments should be 4", () => {
expect(checkArgs(process.argv)).toBe(true)
})
})