Open maplion opened 4 years ago
Are you sure toStrictEqual
comes from jest-extended
? I haven't taken a good look at it but it seems to come from jest
directly:
An issue was created: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36285
@sebranly I will feel sheepish if that is the case, but none of my jest-extended matchers seem to work. (I think) all of my Jest functions both give intellisense and are recognized by the compiler.
Update - I won't confirm it in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36285 until I get it working but actually I'm pretty confident the 24.0.18
package is updated enough to give typings for toStrictEqual
. In my node_modules/@types/jest/index.d.ts
file, I literally see:
/**
* Use to test that objects have the same types as well as structure.
*/
toStrictEqual(expected: {}): R;
I think you have two separate issues:
toStrict
(coming from jest
), which I'm personally interested injest-extended
), which I don't use in my application@sebranly I see what you mean, but I can't even get it to show up in intellisense at all unless I do this at the top of my spec file:
/// <reference path='../../../../test/typings/jest-extended.d.ts' />
That has "import 'jest-extended';" in it and that's when expect('blah').toStrictEqual and other matchers show up; otherwise they are not there and I just have the normal expect('blah').toBe, etc. So I can get the typings in with the janky reference relative path method, but I can't get the typings successfully working in any global way (have tried everything I could find on the web in that regard), but even if I get the typings in, the compiler doesn't recognize them, even though my jest config matches the examples.
Any updates on this? I'm using "ts-jest": "^26.1.0", and also having same issue
@jjcv2304
I just added global
to jest config in package.json
{
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"setupFilesAfterEnv": [
"jest-extended",
"./tests/tests-setup.ts" // includes import 'jest-extended'
],
"globals": { // this did the job
"ts-jest": {
"tsConfig": "tsconfig.json"
}
},
...
}
Does anyone here have @types/jasmine
in their package.json / or lockfiles?
I have a monorepo and this came up for me and it happened around the time I tried to satisfy a dependency with angular (which uses jasmine by default it appears).
If you have any other type declaration file that's competing against jasmine's, even if it's an implicit dependency, please check for it. Use your lockfiles, clear your node_modules and reinstall, etc.
Potentially related: https://github.com/nestjs/nest/issues/4223
Broken with toStrictEqual
error: https://github.com/tony/cv/runs/1636818626
Fixed here: https://github.com/tony/cv/runs/1636861741 https://github.com/tony/cv/commit/8b23c802b0c0c1584b930814a552bffecd785b34
I fixed it with:
diff --git a/package.json b/package.json
index 142c0704..079f2b47 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"github": "yarn workspace @tony/cv-scripts run github"
},
"workspaces": {
+ "nohoist": ["**/@types/jest", "**/@types/jasmine"],
"packages": [
"packages/*"
]
Then rerun npm / yarn, and if that doesn't work clear node_modules/
If this does work, please note it.
But this doesn't necessarily solve all issues w/ this. So let's not close this issue until we're sure it's the only manifestation.
Bug
package
version: 0.11.2node
version: 12.3.1npm
version: 6.11.2typescript
version: 3.5.3Relevant code or config
What you did: I am trying to run a test utilizing a jest-extended matcher function (i.e. toStrictEqual).
What happened (please provide anything you think will help): I cannot get the compiler to recognize jest-extended matchers, no matter what I seem to try; for example: - error TS2339: Property 'toStrictEqual' does not exist on type 'Matchers'.
I have followed everything in the README and here https://github.com/jest-community/jest-extended/issues/172 in order to get the typings to work and they finally seem to work, but I still can't get the compiler to recognize the matcher functions.
Reproduction repository (if possible):
N/A
What am I missing?
Possibly related to https://github.com/jest-community/jest-extended/issues/171 and https://github.com/jest-community/jest-extended/issues/189 which seem to have been ignored.