-
Notifications
You must be signed in to change notification settings - Fork 43
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
Property 'toBeOnTheScreen' does not exist on type 'JestMatchers<ReactTestInstance>' (TS project) #146
Comments
@Aure77 we have an basic example app in RNTL repo that showcases correct config for RNTL + JestNative + TS. Pls compare your config with that. Matchers should be properly exposed for TS. Make sure that you are using the latest version of Jest Native (5.4.1) because of #138. |
@Aure77 I had the same problem, in my setup I had |
Hey, you have forgot to install Thanks, |
I had same issue. All my config files were ok. I fixed it importing: Example:
|
@emflomed17 did you follow the installation instructions at https://github.com/testing-library/jest-native#usage ? In correct setting adding |
I experience the same. It only goes away if like @emflomed17 mentions, you import it on the test or extend expect inline in the test file. The only other thing to mention is I'm in a yarn workspace within a monorepo? Not sure that matters though. The error clearly goes away when you bring in the import line to the test file specifically. The tests all pass whether or not TS has an error about the matcher package.json config
jest-setup.js config
|
@Aure77 @frankcalise @emflomed17 Does the issue affect only |
|
If affects all matchers extended by jest-native, none of them show up in the intellisense / are underlined taht the property doesn't exist. Same for toBeEnabled, toBeDisabled etc. Although, this seemed to help in my
|
With this workaround, you need to add all your types manually (including |
I used a triple slash directive to get the correct types added: /// <reference types="@testing-library/jest-native/extend-expect" /> This was in a |
I was having issues getting types for this and reanimated's jest extensions. My updated file now looks like this: import { JestNativeMatchers } from '@testing-library/jest-native/extend-expect'
declare global {
namespace jest {
interface Matchers<R> extends JestNativeMatchers<R> {
// declaring this here as the library has the wrong typedef
toHaveAnimatedStyle(
style: Record<string, unknown>[] | Record<string, unknown>,
options?: { exact?: boolean },
): R
}
}
} |
Recommended Workarounds 🚑After some investigation I've found that the TS types (
This works because it causes typescript to globally import Jest type extension. ---- OR ----
Not sure why this works, but it works fine with ---- OR ----
This basically disables type-checking on |
TBH I have no idea for "automatic" resolution, that would propagate Jest type extension just by including Perhaps you folks will have any idea: @callumskeet-bom, @Aure77 , @frankcalise how to do such thing. |
I've added the documentation for official TS workarounds: https://github.com/testing-library/jest-native#typescript-support |
@mdjastrzebski thanks for the documentation. As far as the "automatic" resolution, I have to dive deeper into it. However, I know jest-dom adds custom matchers and the setup is documented as so:
|
Talking about VS Code intellisense, I've tried every workaround and only following solutions worked
not sure why the Using latest |
@CptFabulouso could you check if using TS 'jest-setup.ts' + 'include' option in 'tsconfig.json' as describe here solves the issue for you? |
@mdjastrzebski Yes, that change in
|
I had the same issue. The error was the
|
react-native
orexpo
: RN@testing-library/react-native
version: ^11.4.0jest-preset
: "react-native"react-native
version: 0.70.6node
version: 16Relevant code or config:
What you did:
Try to use custom matcher in a TS project that check types with
tsc
.What happened:
Typescript check error.
Reproduction:
Problem description:
Custom matcher of jest-native are not exposed as TS types. So a TS project have issue when build with TS compiler (tsc):
Ex:
Property 'toBeOnTheScreen' does not exist on type 'JestMatchers<ReactTestInstance>' (TS project)
Suggested solution:
expose types in package.json
The text was updated successfully, but these errors were encountered: