Skip to content

Commit 4bb904a

Browse files
committed
add tests for toHaveDisplayValue()
1 parent a4b3b80 commit 4bb904a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as React from 'react';
2+
import { TextInput, View } from 'react-native';
3+
import { render, screen } from '../..';
4+
import '../extend-expect';
5+
6+
test('example test', () => {
7+
render(<TextInput testID="text-input" value="test" />);
8+
9+
const textInput = screen.getByTestId('text-input');
10+
11+
expect(textInput).toHaveDisplayValue('test');
12+
});
13+
14+
test('toHaveDisplayValue() on matching display value', () => {
15+
render(<TextInput testID="text-input" value="test" />);
16+
17+
const textInput = screen.getByTestId('text-input');
18+
19+
expect(textInput).toHaveDisplayValue('test');
20+
});
21+
22+
test('toHaveDisplayValue() on not matching display value', () => {
23+
render(<TextInput testID="text-input" value="test" />);
24+
25+
const textInput = screen.getByTestId('text-input');
26+
27+
expect(textInput).not.toHaveDisplayValue('non-test');
28+
});
29+
30+
test("toHaveDisplayValue() on non 'TextInput' elements", () => {
31+
render(<View testID="view" />);
32+
33+
const view = screen.getByTestId('view');
34+
35+
expect(() =>
36+
expect(view).not.toHaveDisplayValue('test')
37+
).toThrowErrorMatchingInlineSnapshot(
38+
`"toHaveDisplayValue() works only with host "TextInput" elements. Passed element has type "View"."`
39+
);
40+
});
41+
42+
test('toHaveDisplayValue() on matching element with .not', () => {
43+
render(<TextInput testID="text-input" value="test" />);
44+
45+
const textInput = screen.getByTestId('text-input');
46+
47+
expect(() => expect(textInput).not.toHaveDisplayValue('test'))
48+
.toThrowErrorMatchingInlineSnapshot(`
49+
"expect(element).not.toHaveDisplayValue()
50+
51+
Expected element not to have display value:
52+
test
53+
Received:
54+
test"
55+
`);
56+
});
57+
58+
test('toHaveDisplayValue() on not matching element', () => {
59+
render(<TextInput testID="text-input" value="test" />);
60+
61+
const textInput = screen.getByTestId('text-input');
62+
63+
expect(() => expect(textInput).toHaveDisplayValue('non-test'))
64+
.toThrowErrorMatchingInlineSnapshot(`
65+
"expect(element).toHaveDisplayValue()
66+
67+
Expected element to have display value:
68+
non-test
69+
Received:
70+
test"
71+
`);
72+
});

src/matchers/extend-expect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import { toBeOnTheScreen } from './to-be-on-the-screen';
44
import { toBeEmptyElement } from './to-be-empty-element';
5+
import { toHaveDisplayValue } from './to-have-display-value';
56

67
expect.extend({
78
toBeOnTheScreen,
89
toBeEmptyElement,
10+
toHaveDisplayValue,
911
});

0 commit comments

Comments
 (0)