jest-extended
jest-extended copied to clipboard
Property 'toBeArray' does not exist on type JestMatchersShape
Bug
packageversion: 0.11.2nodeversion: 12.13.0npmversion: 6.13.0ts-jestversion: 24.1.0@types/jestversion: 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
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
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.
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.