Skip to content

docs: expose jest matchers publically (docs, examples, etc) #1523

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

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -16,6 +16,5 @@ build
!.yarn/sdks
!.yarn/versions

# Ignore lock files in examples for now
examples/**/yarn.lock
# Docusaurus
.docusaurus
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -50,27 +50,10 @@ This library has a `peerDependencies` listing for `react-test-renderer`. Make su

### Additional Jest matchers

To use additional React Native-specific jest matchers from [@testing-library/jest-native](https://github.com/testing-library/jest-native) package add it to your project:
You can use the built-in Jest matchers by adding the following line to your `jest-setup.ts` file (configured using [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array)):

#### Using `yarn`

```sh
yarn add --dev @testing-library/jest-native
```

#### Using `npm`

```sh
npm install --save-dev @testing-library/jest-native
```

Then automatically add it to your jest tests by using the `setupFilesAfterEnv` option in your Jest configuration (it's usually located either in `package.json` under the `"jest"` key or in a `jest.config.json` file):

```json
{
"preset": "react-native",
"setupFilesAfterEnv": ["@testing-library/jest-native/extend-expect"]
}
```ts
import '@testing-library/react-native/extend-expect';
```

### Custom Jest Preset (React Native before 0.71)
4 changes: 2 additions & 2 deletions examples/basic/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-undef, import/no-extraneous-dependencies */

// Import Jest Native matchers
import '@testing-library/jest-native/extend-expect';
// Import built-in Jest matchers
import '@testing-library/react-native/extend-expect';

// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
3 changes: 1 addition & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -19,8 +19,7 @@
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@testing-library/jest-native": "^5.4.3",
"@testing-library/react-native": "^12.3.2",
"@testing-library/react-native": "^12.3.3",
"@types/react": "~18.2.14",
"jest": "^29.7.0",
"react-test-renderer": "18.2.0",
Loading