Skip to content

Commit 1942629

Browse files
(CR): Address Code Review comments
1 parent fda2999 commit 1942629

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

packages/native/test/lib/ElementAssertion.test.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,32 +288,46 @@ describe("[Unit] ElementAssertion.test.ts", () => {
288288
const parentElementAssertion = new ElementAssertion(parent);
289289
const child = element.getByTestId("childId");
290290
const text = element.getByTestId("textId");
291+
const textElementAssertion = new ElementAssertion(text);
291292

292-
context("when the container element contains the target element", () => {
293-
it("returns the assertion instance", () => {
294-
expect(containerElementAssertion.toContainElement(parent)).toBe(containerElementAssertion);
295-
expect(containerElementAssertion.toContainElement(child)).toBe(containerElementAssertion);
296-
expect(containerElementAssertion.toContainElement(text)).toBe(containerElementAssertion);
297-
expect(parentElementAssertion.toContainElement(child)).toBe(parentElementAssertion);
293+
context("when the element has children", () => {
294+
context("and the target element is found in the children's element", () => {
295+
it("returns the assertion instance", () => {
296+
expect(containerElementAssertion.toContainElement(parent)).toBe(containerElementAssertion);
297+
expect(containerElementAssertion.toContainElement(child)).toBe(containerElementAssertion);
298+
expect(containerElementAssertion.toContainElement(text)).toBe(containerElementAssertion);
299+
expect(parentElementAssertion.toContainElement(child)).toBe(parentElementAssertion);
300+
});
301+
302+
it("throws an error for negative assertion", () => {
303+
expect(() => containerElementAssertion.not.toContainElement(parent))
304+
.toThrowError(AssertionError)
305+
.toHaveMessage("Expected element <View ... /> NOT to contain element <View ... />.");
306+
expect(() => containerElementAssertion.not.toContainElement(text))
307+
.toThrowError(AssertionError)
308+
.toHaveMessage("Expected element <View ... /> NOT to contain element <Text ... />.");
309+
});
298310
});
299311

300-
it("returns the assertion instance for negated assertions when the target element is not contained", () => {
301-
expect(parentElementAssertion.not.toContainElement(text)).toBeEqual(parentElementAssertion);
302-
expect(parentElementAssertion.not.toContainElement(container)).toBeEqual(parentElementAssertion);
312+
context("and the target element is NOT found in the children's element", () => {
313+
it("throws an error", () => {
314+
expect(() => parentElementAssertion.toContainElement(text))
315+
.toThrowError(AssertionError)
316+
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />.");
317+
});
318+
319+
it("returns the assertion instance for negative assertion", () => {
320+
expect(parentElementAssertion.not.toContainElement(text)).toBeEqual(parentElementAssertion);
321+
expect(parentElementAssertion.not.toContainElement(container)).toBeEqual(parentElementAssertion);
322+
});
303323
});
304324
});
305325

306-
context("when the container element does NOT contain the target element", () => {
326+
context("when the element does NOT have children", () => {
307327
it("throws an error", () => {
308-
expect(() => containerElementAssertion.not.toContainElement(parent))
309-
.toThrowError(AssertionError)
310-
.toHaveMessage("Expected element <View ... /> NOT to contain element <View ... />.");
311-
expect(() => containerElementAssertion.not.toContainElement(text))
312-
.toThrowError(AssertionError)
313-
.toHaveMessage("Expected element <View ... /> NOT to contain element <Text ... />.");
314-
expect(() => parentElementAssertion.toContainElement(text))
328+
expect(() => textElementAssertion.toContainElement(parent))
315329
.toThrowError(AssertionError)
316-
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />.");
330+
.toHaveMessage("Expected element <Text ... /> to contain element <View ... />.");
317331
});
318332
});
319333
});

0 commit comments

Comments
 (0)