Skip to content

Commit 0accbc4

Browse files
committed
BREAKING CHANGE: support @testing-library/react-native 7.0
The matchers toBeDisabled and toBeEnabled had to be removed in order to fully support @testing-library/react-native 7.0. The reason for that is because testing-library returns native instances since v2.0 and these matchers were checking the host component a non-native instance. They will be rewritten asserting the logic RN does around `onStartShouldSetResponder` as discussed in #23
1 parent 8a0fbc1 commit 0accbc4

File tree

8 files changed

+5
-261
lines changed

8 files changed

+5
-261
lines changed

README.md

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
- [Installation](#installation)
4141
- [Usage](#usage)
4242
- [Matchers](#matchers)
43-
- [`toBeDisabled`](#tobedisabled)
44-
- [`toBeEnabled`](#tobeenabled)
4543
- [`toBeEmpty`](#tobeempty)
4644
- [`toContainElement`](#tocontainelement)
4745
- [`toHaveProp`](#tohaveprop)
@@ -108,58 +106,6 @@ expect.extend({ toBeEmpty, toHaveTextContent });
108106
`jest-native` has only been tested to work with `RNTL`. Keep in mind that these queries will only
109107
work on UI elements that bridge to native.
110108

111-
### `toBeDisabled`
112-
113-
```javascript
114-
toBeDisabled();
115-
```
116-
117-
Check whether or not an element is disabled from a user perspective.
118-
119-
This matcher will check if the element or its parent has a `disabled` prop, or if it has
120-
`accessibilityState={{disabled: true]}.
121-
122-
It also works with `accessibilityStates={['disabled']}` for now. However, this prop is deprecated in
123-
React Native [0.62](https://reactnative.dev/blog/2020/03/26/version-0.62#breaking-changes)
124-
125-
#### Examples
126-
127-
```javascript
128-
const { getByTestId } = render(
129-
<View>
130-
<Button disabled testID="button" title="submit" onPress={e => e} />
131-
<TextInput accessibilityState={{ disabled: true }} testID="input" value="text" />
132-
</View>,
133-
);
134-
135-
expect(getByTestId('button')).toBeDisabled();
136-
expect(getByTestId('input')).toBeDisabled();
137-
```
138-
139-
### `toBeEnabled`
140-
141-
```javascript
142-
toBeEnabled();
143-
```
144-
145-
Check whether or not an element is enabled from a user perspective.
146-
147-
Works similarly to `expect().not.toBeDisabled()`.
148-
149-
#### Examples
150-
151-
```javascript
152-
const { getByTestId } = render(
153-
<View>
154-
<Button testID="button" title="submit" onPress={e => e} />
155-
<TextInput testID="input" value="text" />
156-
</View>,
157-
);
158-
159-
expect(getByTestId('button')).toBeEnabled();
160-
expect(getByTestId('input')).toBeEnabled();
161-
```
162-
163109
### `toBeEmpty`
164110

165111
```javascript
@@ -231,10 +177,8 @@ const { queryByTestId } = render(
231177
</View>,
232178
);
233179

234-
expect(queryByTestId('button')).toHaveProp('accessibilityStates', ['disabled']);
235-
expect(queryByTestId('button')).toHaveProp('accessible');
236-
expect(queryByTestId('button')).not.toHaveProp('disabled');
237-
expect(queryByTestId('button')).not.toHaveProp('title', 'ok');
180+
expect(queryByTestId('text')).toHaveProp('allowFontScaling', false);
181+
expect(queryByTestId('text')).not.toHaveProp('style');
238182
```
239183

240184
### `toHaveTextContent`

extend-expect.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { ReactTestInstance } from 'react-test-renderer';
33
declare global {
44
namespace jest {
55
interface Matchers<R, T> {
6-
toBeDisabled(): R;
76
toContainElement(element: ReactTestInstance | null): R;
87
toBeEmpty(): R;
98
toHaveProp(attr: string, value?: any): R;
109
toHaveTextContent(text: string | RegExp, options?: { normalizeWhitespace: boolean }): R;
11-
toBeEnabled(): R;
1210
toHaveStyle(style: object[] | object): R;
1311
}
1412
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ignores = ['/node_modules/', '/__tests__/helpers/', '__mocks__'];
22

33
module.exports = {
4-
preset: '@testing-library/react-native',
4+
preset: 'react-native',
55
setupFilesAfterEnv: ['<rootDir>/setup-tests.js'],
66
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
77
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@babel/cli": "7.2.3",
4040
"@babel/core": "7.4.0",
4141
"@babel/runtime": "7.4.0",
42-
"@testing-library/react-native": "^6.0.0",
42+
"@testing-library/react-native": "^7.1.0",
4343
"commitizen": "^3.0.7",
4444
"cz-conventional-changelog": "^2.1.0",
4545
"husky": "^1.3.1",

src/__tests__/to-be-disabled.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/__tests__/to-have-prop.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ test('.toHaveProp', () => {
1212
</View>,
1313
);
1414

15-
expect(queryByTestId('button')).toHaveProp('disabled', true);
16-
expect(queryByTestId('button')).toHaveProp('disabled');
17-
expect(queryByTestId('button')).toHaveProp('title', 'ok');
18-
1915
expect(queryByTestId('text')).toHaveProp('allowFontScaling', false);
2016
expect(queryByTestId('text')).not.toHaveProp('style');
2117

2218
expect(() =>
2319
expect(queryByTestId('button')).toHaveProp('accessibilityStates', ['disabled']),
2420
).toThrowError();
25-
expect(() => expect(queryByTestId('button')).toHaveProp('accessible')).toThrowError();
26-
expect(() => expect(queryByTestId('button')).not.toHaveProp('disabled')).toThrowError();
27-
expect(() => expect(queryByTestId('button')).not.toHaveProp('title', 'ok')).toThrowError();
2821

2922
expect(() =>
3023
expect(queryByTestId('text')).not.toHaveProp('allowFontScaling', false),

src/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import { toBeDisabled, toBeEnabled } from './to-be-disabled';
21
import { toBeEmpty } from './to-be-empty';
32
import { toHaveProp } from './to-have-prop';
43
import { toHaveTextContent } from './to-have-text-content';
54
import { toContainElement } from './to-contain-element';
65
import { toHaveStyle } from './to-have-style';
76

8-
export {
9-
toBeDisabled,
10-
toContainElement,
11-
toBeEmpty,
12-
toHaveProp,
13-
toHaveTextContent,
14-
toBeEnabled,
15-
toHaveStyle,
16-
};
7+
export { toContainElement, toBeEmpty, toHaveProp, toHaveTextContent, toHaveStyle };

src/to-be-disabled.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)