#x
1 messages · Page 1 of 1 (latest)
Based on the information provided in the extracts, it seems like you've done the setup correctly. However, the issue you're facing might be due to TypeScript not recognizing the custom matchers provided by @testing-library/jest-dom.
To solve this, you need to import @testing-library/jest-dom in your test setup file. According to the extracts (https://nextjs.org/docs/pages/building-your-application/optimizing/testing), you can add the import to your jest.setup.js file:
import '@testing-library/jest-dom'
If you're using @testing-library/jest-dom before version 6, you will need to import @testing-library/jest-dom/extend-expect instead.
Also, ensure that your jest.config.js file includes the setup file:
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
If you've done all of this and the issue persists, it might be a TypeScript issue. You can try adding the following line to a TypeScript declaration file (like next-env.d.ts or jest.d.ts in your project root):
/// <reference types="@testing-library/jest-dom" />
This line will help TypeScript recognize the custom matchers from @testing-library/jest-dom.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@errant reef kapa.ai is still learning and improving, please let us know how it did by reacting below