|
| 1 | +import { View, Text, TextInput, Pressable, TouchableOpacity } from 'react-native'; |
1 | 2 | import { checkReactElement, isEmpty } from '../utils';
|
2 | 3 |
|
3 | 4 | describe('checkReactElement', () => {
|
4 |
| - test('it does not throw an error for valid native primitives', () => { |
5 |
| - expect(() => { |
6 |
| - // @ts-expect-error Argument of type '{ type: "text"; }' is not assignable to parameter of type 'ReactTestInstance'. Type '{ type: "text"; }' is missing the following properties from type 'ReactTestInstance': instance, props, parent, children, and 6 more.ts(2345) |
7 |
| - checkReactElement({ type: 'Text' }, () => {}, null); |
8 |
| - }).not.toThrow(); |
| 5 | + test('ReactTestInstance does not throw for host elements', () => { |
| 6 | + expect(() => |
| 7 | + // @ts-expect-error Passing incorrect Jest Matcher data |
| 8 | + checkReactElement({ type: 'View' }, () => {}, {}), |
| 9 | + ).not.toThrow(); |
| 10 | + expect(() => |
| 11 | + // @ts-expect-error Passing incorrect Jest Matcher data |
| 12 | + checkReactElement({ type: 'TextInput' }, () => {}, {}), |
| 13 | + ).not.toThrow(); |
| 14 | + expect(() => |
| 15 | + // @ts-expect-error Passing incorrect Jest Matcher data |
| 16 | + checkReactElement({ type: 'View' }, () => {}, {}), |
| 17 | + ).not.toThrow(); |
9 | 18 | });
|
10 | 19 |
|
11 |
| - test('ReactTestInstance does not throw', () => { |
12 |
| - expect(() => { |
13 |
| - // @ts-expect-error Argument of type '{ _fiber: {}; }' is not assignable to parameter of type 'ReactTestInstance'. Object literal may only specify known properties, and '_fiber' does not exist in type 'ReactTestInstance'.ts(2345) |
14 |
| - checkReactElement({ _fiber: {} }, () => {}, null); |
15 |
| - }).not.toThrow(); |
| 20 | + test('ReactTestInstance does not throw for composite Text elements', () => { |
| 21 | + expect(() => |
| 22 | + // @ts-expect-error Passing incorrect Jest Matcher data |
| 23 | + checkReactElement({ type: Text }, () => {}, {}), |
| 24 | + ).not.toThrow(); |
16 | 25 | });
|
17 | 26 |
|
18 |
| - test('it does throw an error for invalid native primitives', () => { |
19 |
| - expect(() => { |
20 |
| - // @ts-expect-error Argument of type '{ type: "button"; }' is not assignable to parameter of type 'ReactTestInstance'. Type '{ type: "button"; }' is missing the following properties from type 'ReactTestInstance': instance, props, parent, children, and 6 more.ts(2345) |
21 |
| - checkReactElement({ type: 'Button' }, () => {}, null); |
22 |
| - }).toThrow(); |
| 27 | + test('ReactTestInstance does not throw for composite TextInput elements', () => { |
| 28 | + expect(() => |
| 29 | + // @ts-expect-error Passing incorrect Jest Matcher data |
| 30 | + checkReactElement({ type: TextInput }, () => {}, {}), |
| 31 | + ).not.toThrow(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('it does throw for composite elements', () => { |
| 35 | + expect(() => |
| 36 | + // @ts-expect-error Incorrect Test Renderer typings |
| 37 | + checkReactElement({ type: View }, () => {}, {}), |
| 38 | + ).toThrowErrorMatchingInlineSnapshot(` |
| 39 | + "expect(received).() |
| 40 | +
|
| 41 | + received value must be a host element or composite Text/TextInput element |
| 42 | + Received has type: object |
| 43 | + Received has value: {"type": [Function Component]}" |
| 44 | + `); |
| 45 | + expect(() => |
| 46 | + // @ts-expect-error Incorrect Test Renderer typings |
| 47 | + checkReactElement({ type: Pressable }, () => {}, {}), |
| 48 | + ).toThrowErrorMatchingInlineSnapshot(` |
| 49 | + "expect(received).() |
| 50 | +
|
| 51 | + received value must be a host element or composite Text/TextInput element |
| 52 | + Received has type: object |
| 53 | + Received has value: {"type": {"$$typeof": Symbol(react.memo), "compare": null, "type": {"$$typeof": Symbol(react.forward_ref), "render": [Function Pressable]}}}" |
| 54 | + `); |
| 55 | + expect(() => |
| 56 | + // @ts-expect-error Incorrect Test Renderer typings |
| 57 | + checkReactElement({ type: TouchableOpacity }, () => {}, {}), |
| 58 | + ).toThrowErrorMatchingInlineSnapshot(` |
| 59 | + "expect(received).() |
| 60 | +
|
| 61 | + received value must be a host element or composite Text/TextInput element |
| 62 | + Received has type: object |
| 63 | + Received has value: {"type": {"$$typeof": Symbol(react.forward_ref), "render": [Function anonymous]}}" |
| 64 | + `); |
23 | 65 | });
|
24 | 66 | });
|
25 | 67 |
|
|
0 commit comments