-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
expect
triggers incompatibility with mocha declarations
#8570
Comments
reopening as per discussion in #9209 |
I had to separate expect from jest types manually in my repo. Of course it's an ugly solution but there are no alternatives at this point https://github.com/webdriverio/expect-webdriverio/blob/master/types/jest-expect-clone/jest-expect.d.ts It's possible to keep jest and expect types in same repo and access types like this @types/jest/expect or have @types/expect separately, then jest types can have expect types as dependency |
I think I figured it out. Jest is not augmenting However, other type declarations might augment When Jest tries to declare an interface that extends I think this is the solution, which goes in
By using If another jest declaration file really does want to declare globals, it should be able to do something like |
That seems reasonable to me - wanna send a PR with it? |
Sure thing; done. |
I have this same issue, but with the latest versions of jest and mocha. I've created this repository to reproduce the issue: jdbruijn/jest-mocha-conflict. It looked to be the same issue as reported here, which was presumably fixed. If it is not, I can open a new issue or something like that. node --version
v13.13.0 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Trying to use the
expect
assertion library on a mocha project causes TypeScript errors, even though there should not be any incompatibility.Both
@types/mocha
and@jest/types
try to declare incompatible global TS declarations forit
,describe
, etc, which causes TS compiler errors. Obviously users should not try to load both of these at once. However, theexpect
type declarations refer to@jest/types
. This means it's impossible to use theexpect
assertion library in a project that uses mocha as its test runner.I think the solution is straightforward:
@jest/types
so it's possible to import@jest/types/no-global
which will not augment global interfaces.expect
to import types from@jest/types/no-global
instead of@jest/types
This can be fully backwards compatible.
To Reproduce
Steps to reproduce the behavior:
Set
"types": ["mocha"]
in the tsconfig file to avoid eagerly loading unrelated@types
.You'll see the following TypeScript error:
Expected behavior
Importing
expect
in a TS project does not augment global interfaces with Jest-specific type declarations.Link to repl or repo (highly encouraged)
https://repl.it/repls/SpanishHugeVirus
Run
npx envinfo --preset jest
Paste the results here:
System: OS: Linux 4.9 Pengwin undefined CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz Binaries: Node: 10.15.2 - /usr/bin/node Yarn: 1.16.0 - /usr/bin/yarn npm: 6.9.0 - ~/n/bin/npm
The text was updated successfully, but these errors were encountered: