Pavel
Pavel

Reputation: 2564

ReferenceError: describe is not defined in Jest + Typescript

Simple configuration of Jest with ts-jest produces error "ReferenceError: describe is not defined" in runtime. Here minimal example: https://github.com/PFight/jest-ts-describe-not-defined-problem

What I configured wrong?

Upvotes: 6

Views: 16954

Answers (5)

Muhammed Moussa
Muhammed Moussa

Reputation: 5205

Wired answer but may help someone. but in my case @types, tsconfig, and everything was ok and I still have the error, by the end, I figured that spec and test are in exclude array in tsconfig removed it and the error is gone.

Upvotes: 0

GreatPyrenees
GreatPyrenees

Reputation: 186

I had the same problem but I needed the testEnvironment to be node. The solution is to downgrade to "jest": "^24.9.0". It seems like there's a problem with the latest version when testEnvironment is set to node.

UPDATE

It looks like this issue has been fixed in jest 25.2.2 per this comment https://github.com/facebook/jest/issues/9538#issuecomment-604522345 I haven't tested it though.

Upvotes: 5

ocknamo-bb
ocknamo-bb

Reputation: 111

I had same problem in node v10.14.1.

Just update node to v10.16.2 and error was fixed.

Upvotes: 8

Max
Max

Reputation: 1523

Or you can add the type definitions for jest like this in your tsconfig: "include": ["node_modules/@types", "test/**/**.ts"],

And add the types via installing it with npm -i @types/jest

I can't push to your repo though creating a PR is not possible..

Upvotes: 4

Pavel
Pavel

Reputation: 2564

Found the problem. It was next row in jest.config.js:

testEnvironment: 'node',

Just removed it and error was fixed.

Upvotes: 7

Related Questions