TS2582

error TS2582: Cannot find name ‘test’. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha.

Broken Code ❌

1
2
3
test('create sum', () => {
expect(1 + 2).toBe(3);
});

Fixed Code ✔️

The error above is very specific to your testing framework and when using Jest it can be easily solved by installing definition files for Jest (npm i --save-dev @types/jest).

When you are using Playwright, then you would have to make sure that you properly import Playwright’s definition for test:

1
2
3
4
5
import {test, expect} from '@playwright/test';

test('create sum', () => {
expect(1 + 2).toBe(3);
});