Description
Describe the bug
dist/matchers/to-have-style.d.ts types the matcher's this as jest.MatcherContext, a member of the global jest namespace that only @types/jest declares. The package's own declare global { namespace jest … } in dist/matchers/types.d.ts declares Matchers and not MatcherContext, and @types/jest is neither a dependency nor a peer dependency. So a TypeScript project that imports @testing-library/react-native without @types/jest (a Jest project that imports its globals from @jest/globals, or a Vitest one) fails its type check under skipLibCheck: false:
node_modules/@testing-library/react-native/dist/matchers/to-have-style.d.ts(4,48): error TS2694: Namespace 'global.jest' has no exported member 'MatcherContext'.
Expected behavior
Importing @testing-library/react-native type-checks in a project without @types/jest, and toHaveStyle keeps its types where Jest's are loaded.
Steps to Reproduce
- In an empty folder, install the package and its peers, without
@types/jest:npm install @testing-library/react-native@14.1.0 react@19.1.0 react-native@0.79.7 test-renderer@1.3.1 typescript@5 @types/react@19
- Add
tsconfig.json:{ "compilerOptions": { "strict": true, "skipLibCheck": false, "noEmit": true, "target": "ES2022", "lib": ["ES2022"], "module": "preserve", "moduleResolution": "bundler", "jsx": "react-jsx", "types": [] }, "files": ["render.tsx"] } - Add
render.tsx:import { render, screen } from '@testing-library/react-native'; import { Text } from 'react-native'; export const renderHello = async (): Promise<void> => { await render(<Text>Hello</Text>); screen.getByText('Hello'); };
- Run
npx tsc -p .
Expected: no output. Actual: the TS2694 error above.
Reproducer: https://gist.github.com/YevheniiKotyrlo/49628750d2dc1a8fe98c14d74983e926. node repro.mjs builds main (564a842), packs it, runs the steps above, and exits 1 while the error shows:
@testing-library/react-native main at 564a842 (2026-11-05)
== tsc --noEmit
node_modules/@testing-library/react-native/dist/matchers/to-have-style.d.ts(4,48): error TS2694: Namespace 'global.jest' has no exported member 'MatcherContext'.
RESULT: the package's types need Jest's global jest namespace (TS2694)
React Native 0.79.7 keeps the output to this one error: 0.88.1's own declarations fail the same check (react/react-native#59647).
Screenshots
None.
Versions
npmPackages:
@testing-library/react-native: file:../testing-library-react-native-14.1.0.tgz => 14.1.0
react: ^19.1.0 => 19.1.0
react-native: ^0.79.7 => 0.79.7
test-renderer: ^1.3.1 => 1.3.1
typescript Version 5.9.3
Activity
YevheniiKotyrlo commentedon Nov 12, 2026
The patch I apply to 14.1.0 types
toHaveStyle'sthiswith the two members it reads,isNotandequals, so the declaration names nojestnamespace: