|
| 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 | +}); |
0 commit comments