|
1 |
| -import { render } from "@testing-library/react-native"; |
| 1 | +import { AssertionError, expect } from "@assertive-ts/core"; |
| 2 | +import { render, screen } from "@testing-library/react-native"; |
2 | 3 | import {
|
3 |
| - TouchableHighlight, |
4 |
| - TouchableWithoutFeedback, |
5 |
| - TouchableNativeFeedback, |
6 | 4 | View,
|
7 | 5 | TextInput,
|
8 |
| - Pressable, |
9 | 6 | } from "react-native";
|
10 | 7 |
|
11 | 8 | import { ElementAssertion } from "../../src/lib/ElementAssertion";
|
12 | 9 |
|
13 |
| -import assert, { AssertionError } from "assert"; |
14 |
| - |
15 |
| -const ALLOWED_COMPONENTS = { |
16 |
| - Pressable, |
17 |
| - TextInput, |
18 |
| - TouchableHighlight, |
19 |
| - TouchableNativeFeedback, |
20 |
| - TouchableWithoutFeedback, |
21 |
| - View, |
22 |
| -}; |
23 |
| - |
24 | 10 | describe("[Unit] ElementAssertion.test.ts", () => {
|
25 | 11 | describe(".toBeDisabled", () => {
|
26 |
| - context("when the component TextInput is disabled", () => { |
27 |
| - it("returns the assertion instance", () => { |
28 |
| - const element = render( |
29 |
| - <TextInput testID="id" editable={false} />, |
30 |
| - ); |
31 |
| - const test = new ElementAssertion(element.getByTestId("id")); |
32 |
| - |
33 |
| - assert.deepStrictEqual(test.toBeDisabled(), test); |
34 |
| - assert.throws(() => test.not.toBeDisabled(), { |
35 |
| - message: "Expected the value NOT to be disabled", |
36 |
| - name: AssertionError.name, |
37 |
| - }); |
38 |
| - }); |
| 12 | + it("returns the assertion instance when the component TextInput is not editable", () => { |
| 13 | + const element = render( |
| 14 | + <TextInput testID="id" editable={false} />, |
| 15 | + ); |
| 16 | + const test = new ElementAssertion(element.getByTestId("id")); |
| 17 | + |
| 18 | + expect(test.toBeDisabled()).toBe(test); |
| 19 | + expect(() => test.not.toBeDisabled()) |
| 20 | + .toThrowError(AssertionError) |
| 21 | + .toHaveMessage("Expected the value NOT to be disabled"); |
| 22 | + }); |
| 23 | + |
| 24 | + it("checks aria-disabled prop for parent and child element", () => { |
| 25 | + const element = render( |
| 26 | + <View aria-disabled={true} testID="parentId"> |
| 27 | + <View testID="childId"> |
| 28 | + <TextInput /> |
| 29 | + </View> |
| 30 | + </View>, |
| 31 | + ); |
| 32 | + |
| 33 | + const parent = new ElementAssertion(element.getByTestId("parentId")); |
| 34 | + const child = new ElementAssertion(element.getByTestId("childId")); |
| 35 | + |
| 36 | + expect(parent.toBeDisabled()).toBeTruthy(); |
| 37 | + expect(child.toBeDisabled()).toBeTruthy(); |
| 38 | + expect(() => parent.not.toBeDisabled()) |
| 39 | + .toThrowError(AssertionError) |
| 40 | + .toHaveMessage("Expected the value NOT to be disabled"); |
| 41 | + expect(() => child.not.toBeDisabled()) |
| 42 | + .toThrowError(AssertionError) |
| 43 | + .toHaveMessage("Expected the value NOT to be disabled"); |
| 44 | + |
39 | 45 | });
|
40 | 46 |
|
41 |
| - Object.entries(ALLOWED_COMPONENTS).forEach(([name, Component]) => { |
42 |
| - it(`handle disabled prop for element ${name}`, () => { |
43 |
| - const element = render( |
44 |
| - // @ts-expect-error JSX element 'Component' |
45 |
| - <Component disabled={true} testID={name}> |
| 47 | + it("checks aria-disabled prop for child element", () => { |
| 48 | + const element = render( |
| 49 | + <View testID="parentId"> |
| 50 | + <View aria-disabled={true} testID="childId"> |
46 | 51 | <TextInput />
|
47 |
| - </Component>, |
48 |
| - ); |
49 |
| - const test = new ElementAssertion(element.getByTestId(name)); |
50 |
| - assert.deepStrictEqual(test.toBeDisabled(), test); |
51 |
| - assert.throws(() => test.not.toBeDisabled(), { |
52 |
| - message: "Expected the value NOT to be disabled", |
53 |
| - name: AssertionError.name, |
54 |
| - }); |
55 |
| - }); |
| 52 | + </View> |
| 53 | + </View>, |
| 54 | + ); |
| 55 | + |
| 56 | + const parent = new ElementAssertion(element.getByTestId("parentId")); |
| 57 | + const child = new ElementAssertion(element.getByTestId("childId")); |
| 58 | + |
| 59 | + expect(child.toBeDisabled()).toBeTruthy(); |
| 60 | + expect(parent.not.toBeDisabled()).toBeTruthy(); |
| 61 | + expect(() => child.not.toBeDisabled()) |
| 62 | + .toThrowError(AssertionError) |
| 63 | + .toHaveMessage("Expected the value NOT to be disabled"); |
| 64 | + |
56 | 65 | });
|
57 | 66 | });
|
58 | 67 | });
|
0 commit comments