Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom matchers are working when running my tests, but not available in my typedefs/autocomplete in vscode#670

Unanswered
thepuzzlemaster asked this question inQ&A
Discussion options

I'm trying to add custom jest matchers to my Angular project. It seems like everything is set up correctly, but I can't get vscode to recognize the custom matchers in my spec files. If I manuallyimport '@testing-library/jest-dom'; in my test file, then it works fine. But if I try to rely on that import coming from myjest-setup.ts file, I get red squiggles on my custom matchers. If I run the tests, they all pass with the custom matchers, so the import from my setup file is working. But it's just not being recognized by vscode. I've tried restarting the IDE, and resetting the TS server, but no changes there.

And my test file in question is located at:src/components/user-menu/user-menu.component.spec.ts

Any thoughts what might be going on here?

My tsconfig.spec.json:

{  "extends": "./tsconfig.json",  "compilerOptions": {    "outDir": "./out-tsc/spec",    "types": ["jest", "@testing-library/jest-dom", "node"]  },  "files": ["./jest-setup.ts", "src/polyfills.ts"],  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]}

My jest-setup.ts:

import "@testing-library/jest-dom";import { setupZoneTestEnv } from "jest-preset-angular/setup-env/zone";setupZoneTestEnv();
You must be logged in to vote

Replies: 1 comment

Comment options

Ugh. I needed to install the typedefs 🤦
npm i -D @types/testing-library__jest-dom

Sadly, this wasn't showing up as an error in my tsconfig.spec.json, but when I tried adding thetypes array to my base tsconfig.json, the IDE alerted me that it couldn't find type definitions for jest-dom. I'm not sure why that wasn't showing up in my tsconfig.spec.json file.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@thepuzzlemaster

[8]ページ先頭

©2009-2025 Movatter.jp