Skip to content

Commit

Permalink
docs: expose jest matchers publically (docs, examples, etc) (#1523)
Browse files Browse the repository at this point in the history
* docs: update references to Jest Native

* chore: update docs

* chore: update example apps

* docs: update

* chore: upgrade example apps

* chore: self code review

* chore: docs tweaks

* docs: code review changes
  • Loading branch information
mdjastrzebski authored Nov 14, 2023
1 parent bc1ec0d commit 2bce396
Show file tree
Hide file tree
Showing 26 changed files with 25,856 additions and 166 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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)
Expand Down
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
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 2bce396

Please sign in to comment.