Skip to content

Commit 972d6e3

Browse files
siepramdjastrzebski
authored andcommitted
test: negative case
1 parent d645738 commit 972d6e3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/matchers/__tests__/to-contain-element.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ test('toContainElement() supports basic case', () => {
3232
`);
3333
});
3434

35+
test('toContainElement() supports negative case', () => {
36+
render(
37+
<>
38+
<View testID="view1" />
39+
<View testID="view2" />
40+
</>
41+
);
42+
43+
const view1 = screen.getByTestId('view1');
44+
const view2 = screen.getByTestId('view2');
45+
46+
expect(view1).not.toContainElement(view2);
47+
48+
expect(() => expect(view1).toContainElement(view2))
49+
.toThrowErrorMatchingInlineSnapshot(`
50+
"expect(element).toContainElement(element)
51+
52+
<View
53+
testID="view1"
54+
/>
55+
56+
does not contain:
57+
58+
<View
59+
testID="view2"
60+
/>
61+
"
62+
`);
63+
});
64+
3565
test('toContainElement() passing null', () => {
3666
render(<View testID="view" />);
3767

0 commit comments

Comments
 (0)