Skip to content

Commit

Permalink
feat: automatically extend matchers (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski authored Oct 24, 2024
1 parent c7f9132 commit 7455b21
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 14 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ This library has a `peerDependencies` listing for `react-test-renderer`. Make su

### Additional Jest matchers

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)):

```ts
import '@testing-library/react-native/extend-expect';
```
You can use the built-in Jest matchers automatically by having any import from `@testing-library/react-native` in your test.

## Example

Expand Down
1 change: 0 additions & 1 deletion extend-expect.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion extend-expect.js

This file was deleted.

1 change: 0 additions & 1 deletion jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { resetToDefaults } from './src/pure';
import './src/matchers/extend-expect';

beforeEach(() => {
resetToDefaults();
Expand Down
1 change: 1 addition & 0 deletions matchers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './build/matchers';
2 changes: 2 additions & 0 deletions matchers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// makes it so people can import from '@testing-library/react-native/pure'
module.exports = require('./build/matchers');
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"files": [
"build/",
"jest-preset/",
"extend-expect.js",
"extend-expect.d.ts",
"matchers.js",
"matchers.d.ts",
"pure.js",
"pure.d.ts",
"dont-cleanup-after-each.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cleanup } from './pure';
import { flushMicroTasks } from './flush-micro-tasks';
import { getIsReactActEnvironment, setReactActEnvironment } from './act';
import './matchers/extend-expect';

if (!process?.env?.RNTL_SKIP_AUTO_CLEANUP) {
// If we're running in a test runner that supports afterEach
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/__tests__/to-be-checked.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { type AccessibilityRole, Switch, View } from 'react-native';
import render from '../../render';
import { screen } from '../../screen';
import { render, screen } from '../..';

function renderViewsWithRole(role: AccessibilityRole) {
render(
Expand Down
3 changes: 1 addition & 2 deletions src/matchers/__tests__/to-be-partially-checked.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { type AccessibilityRole, View } from 'react-native';
import render from '../../render';
import { screen } from '../../screen';
import { render, screen } from '../..';

function renderViewsWithRole(role: AccessibilityRole) {
return render(
Expand Down

0 comments on commit 7455b21

Please sign in to comment.