Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2304: Cannot find name 'JestMatchers'. #69

Open
panzi opened this issue Apr 26, 2023 · 3 comments
Open

TS2304: Cannot find name 'JestMatchers'. #69

panzi opened this issue Apr 26, 2023 · 3 comments

Comments

@panzi
Copy link

panzi commented Apr 26, 2023

Bug

  • package version: 1.1.0
  • node version: 18.12.1
  • npm version: 8.19.2

What you did:

jest.config.js

module.exports = {
    preset: 'ts-jest',
    testEnvironment: 'node',
    transform: {
      '^.+\\.ts?$': 'ts-jest',
    },
    testMatch: [ "<rootDir>/src/test/**/*.tests.[jt]s?(x)" ],
    transformIgnorePatterns: ['<rootDir>/node_modules/'],
    setupFilesAfterEnv: ["jest-expect-message"],
};

tsconfig.json

{
	"compilerOptions": {
		"target": "es2020",
		"lib": ["es2022"],
		"module": "commonjs",
		"outDir": "dist",
		"sourceMap": true,
		"experimentalDecorators": true,
		"allowJs": true,
		"noImplicitThis": true,
		"strictNullChecks": true,
		"moduleResolution": "node",
		"strictPropertyInitialization": true,
		"useUnknownInCatchVariables": true,
		"baseUrl": ".",
		"paths": {
			"*": [
				"node_modules/*",
				"@types/*"
			]
		},
		"types": ["node"]
	},
	"include": [
		"src/**/*.ts",
		"src/**/*.js"
	],
	"exclude": [
		"node_modules"
	],
	"files": ["node_modules/jest-expect-message/types/index.d.ts"]
}

Then in my tests:

expect(response.success, "my message").toEqual(true);

Then when running npx tsc I get:

node_modules/jest-expect-message/types/index.d.ts:7:8 - error TS2304: Cannot find name 'JestMatchers'.

7     ): JestMatchers<T>;
         ~~~~~~~~~~~~

src/test/tests/api.ts:1092:42 - error TS2554: Expected 1 arguments, but got 2.

1092                 expect(response.success, "my message").toEqual(true);
                                              ~~~~~~~~~~~~
@mrazauskas
Copy link

Do you have @types/jest package installed?

@mrazauskas
Copy link

mrazauskas commented Aug 28, 2023

Ah.. Might be you have, but it is not included in the "types" list (i.e. not visible for TypeScript):

{
  "compilerOptions": {
-   "types": ["node"]
+   "types": ["jest", "node"]
}

@Fleetrun10
Copy link

Thread's dead, but for anyone with the same issue, I did find adding interface JestMatchers<T> extends Matchers<T> {} seemed to fix Intellisense, since Matchers seems to be what's showing up in @types/jest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants