Comments (12)
It seems like referencing this library directly from within the jest config causes the types not to be loaded. I guess this is how jest & TypeScript together works, not sure if there is a way to automatically fix it.
But a simple workaround is to point the script to a TypeScript file that just imports the library:
Change from this:
// jest.config.js
module.exports = {
// [...]
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
};
To this:
// jest.setupFilesAfterEnv.ts
import '@testing-library/jest-native/extend-expect'
// jest.config.js
module.exports = {
// [...]
setupFilesAfterEnv: ['<rootDir>/jest.setupFilesAfterEnv.ts'],
};
from jest-native.
Try adding import '@testing-library/jest-dom'
to your test file, itβs what got rid of the error for me.
from jest-native.
Related: #7
One more thing worth mentioning (in case it wasn't obvious):
Make sure the test setup file ends in.ts
(or.tsx
), and is not excluded in the default tsconfig used by your IDE (e.g. by sitting in a directory that is part ofexclude
intsconfig.json
).it works, but it will cause
setup.ts
to be builded
That's correct. If your project is published and you want to only ship compiled source files (not tests or setup.ts), then you would need two separate tsconfig.json
files. For example, one tsconfig.release.json
extending tsconfig.json
, which excludes tests. In your package.json
you'd have a build
script like: tsc -p tsconfig.release.json
. Your IDE will pick up tsconfig.json
which includes tests to function properly.
from jest-native.
Related: #7
One more thing worth mentioning (in case it wasn't obvious):
Make sure the test setup file ends in .ts
(or .tsx
), and is not excluded in the default tsconfig used by your IDE (e.g. by sitting in a directory that is part of exclude
in tsconfig.json
).
from jest-native.
from jest-native.
This problem also happened with me when I added "include": ["src/**/*"]
to the tsconfig.json
from jest-native.
Related: #7
One more thing worth mentioning (in case it wasn't obvious):
Make sure the test setup file ends in
.ts
(or.tsx
), and is not excluded in the default tsconfig used by your IDE (e.g. by sitting in a directory that is part ofexclude
intsconfig.json
).
it works, but it will cause setup.ts
to be builded
from jest-native.
Closing as stale.
@jorgeruvalcaba If the issue persists with the latest release v5.0.0. Please submit a new issue with minimal repro repository. For our convenience please use examples/basic
from React Native Testing Library as a base for the PR.
from jest-native.
Have the same problem. Using jest-expo
and typescript test file with explicit jest import.
Suggested solution doesn't work.
from jest-native.
@alexamy Please submit a new issue with minimal repro repository. For convenience please use examples/basic from React Native Testing Library as a base for the PR.
from jest-native.
New issue: #136
from jest-native.
In my case, I just converted the jest.config.js
to jest.config.ts
and instead of required('@testing-library/jest-dom')
import '@testing-library/jest-dom'
.
// jest.config.js
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
...
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
...
}
// jest.setup.ts
import '@testing-library/jest-dom'
from jest-native.
Related Issues (20)
- ToBeEmpty assertion in jest-native is also used in jest-extended HOT 2
- toHaveStyle breaks if style is a nested array HOT 2
- Matcher toBeDisabled does not take into account the editable prop of TextInput HOT 3
- Missing (dist) index.js which exports all matchers for library usage HOT 4
- toBeVisible failing when used on Pressable with style function HOT 1
- Property 'toHaveTextContent' does not exist on type 'Matchers<void> & ...' (and any other matcher from library) HOT 15
- Add toBeOnTheScreen matcher to src/index exports HOT 2
- toBeOnTheScreen() not Working With React-Native HOT 5
- toBeEmptyElement isn't working as expected HOT 2
- Peer dependency error after upgrading React to 18.1.0 HOT 5
- Property 'toBeOnTheScreen' does not exist on type 'JestMatchers<ReactTestInstance>' (TS project) HOT 20
- toHaveAccessibilityValue always truthy HOT 4
- toBeVisible ignores opacity via color property HOT 2
- Using toBeOnTheScreen() matcher requires @testing-library/react-native v10.1.0 or later to be added to your devDependencies HOT 2
- Property 'toHaveTextContent' does not exist on type 'JestMatchers<ReactTestInstance | null>'.ts(2339) HOT 2
- Cerate an eslint plugin to sudgest to use alternative jest matchers. HOT 2
- "SyntaxError: Cannot use import statement outside a module" after upgrading to react-native 0.72.4 HOT 3
- Add support for aria properties HOT 1
- refactor: migrate code to TypeScript HOT 1
- refactor: remove Ramda dependency HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-native.