jest-extended icon indicating copy to clipboard operation
jest-extended copied to clipboard

Property 'toBeArray' does not exist on type JestMatchersShape

Open hasezoey opened this issue 6 years ago • 3 comments

Bug

  • package version: 0.11.2
  • node version: 12.13.0
  • npm version: 6.13.0
  • ts-jest version: 24.1.0
  • @types/jest version: 24.0.22

Relevant code or config

jest config (package.json):

{
	"moduleFileExtensions": [
		"js",
		"json",
		"ts"
	],
	"rootDir": "tests",
	"testRegex": ".test.ts$",
	"transform": {
		"^.+\\.(t|j)s$": "ts-jest"
	},
	"coverageDirectory": "./coverage",
	"testEnvironment": "node",
	"setupFilesAfterEnv": [
		"jest-extended"
	]
}

code:

it("should run", () => {
  expect([]).toBeArray();
});

What you did: run jest

What happened: compiler errored, because of mismatching types

TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    tests/tokenizer.test.ts:8:18 - error TS2339: Property 'toBeArray' does not exist on type 'JestMatchersShape<Matchers<void, Token[]>, Matchers<Promise<void>, Token[]>>'.

 	expect(output).toBeArray();

(Token is a class)

but my editor (vscode) has the types fully available

Note: when running the tsc compiler for the tests (no ts-jest), it still complains

PS: i already tried #235, but this did not fix it

PPS: when setting ts-jest's diagnostics to off (/ ignore), the test would run just fine

hasezoey avatar Nov 07 '19 12:11 hasezoey

ok, fixed it with a globals.d.ts and import "jest-extended" - but i thought this is just to get intellisense in the editor - which i had already ...

PS: i will let this open for investigation - because this dosnt seem right

hasezoey avatar Nov 07 '19 12:11 hasezoey

Is there any progress on this investigation? We ran into this all of a sudden, and can't explain why it just decided to stop working.

bamapookie avatar Apr 05 '21 18:04 bamapookie

I have found that having the import in any test file just once alleviates the problem. It doesn't need to be in a global file. And that file does not need to be added to the tsconfig.json files section.

bamapookie avatar Apr 08 '21 15:04 bamapookie