|
| 1 | +import { AssertionError, expect } from "@assertive-ts/core"; |
| 2 | +import { render } from "@testing-library/react-native"; |
| 3 | +import { View, Text } from "react-native"; |
| 4 | + |
| 5 | +import { ToBeEmptyElementAssertion } from "../../src/lib/ToBeEmptyElementAssertion"; |
| 6 | + |
| 7 | +describe("[Unit] ToBeEmptyElementAssertion.test.ts", () => { |
| 8 | + describe(".toBeEmptyElement", () => { |
| 9 | + context("when the element is empty", () => { |
| 10 | + it("returns the assertion instance", () => { |
| 11 | + const element = render(<View testID="id" />); |
| 12 | + const test = new ToBeEmptyElementAssertion(element.getByTestId("id")); |
| 13 | + |
| 14 | + expect(test.toBeEmptyElement()).toBe(test); |
| 15 | + expect(() => test.not.toBeEmptyElement()) |
| 16 | + .toThrowError(AssertionError) |
| 17 | + .toHaveMessage("Expected element <View ... /> to NOT be empty."); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + context("when the element is NOT empty", () => { |
| 22 | + it("throws an error", () => { |
| 23 | + const element = render( |
| 24 | + <View testID="id"> |
| 25 | + <Text>{"Not empty"}</Text> |
| 26 | + </View>, |
| 27 | + ); |
| 28 | + const test = new ToBeEmptyElementAssertion(element.getByTestId("id")); |
| 29 | + |
| 30 | + expect(test.not.toBeEmptyElement()).toBeEqual(test); |
| 31 | + expect(() => test.toBeEmptyElement()) |
| 32 | + .toThrowError(AssertionError) |
| 33 | + .toHaveMessage("Expected element <View ... /> to be empty."); |
| 34 | + }); |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments