Skip to content

Commit 84baa60

Browse files
kdquistanchalalopenchi
authored andcommitted
(CR): Address Code Review comments
1 parent cbe8895 commit 84baa60

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
@@ -328,32 +328,46 @@ describe("[Unit] ElementAssertion.test.ts", () => {
328328
const parentElementAssertion = new ElementAssertion(parent);
329329
const child = element.getByTestId("childId");
330330
const text = element.getByTestId("textId");
331+
const textElementAssertion = new ElementAssertion(text);
331332

332-
context("when the container element contains the target element", () => {
333-
it("returns the assertion instance", () => {
334-
expect(containerElementAssertion.toContainElement(parent)).toBe(containerElementAssertion);
335-
expect(containerElementAssertion.toContainElement(child)).toBe(containerElementAssertion);
336-
expect(containerElementAssertion.toContainElement(text)).toBe(containerElementAssertion);
337-
expect(parentElementAssertion.toContainElement(child)).toBe(parentElementAssertion);
333+
context("when the element has children", () => {
334+
context("and the target element is found in the children's element", () => {
335+
it("returns the assertion instance", () => {
336+
expect(containerElementAssertion.toContainElement(parent)).toBe(containerElementAssertion);
337+
expect(containerElementAssertion.toContainElement(child)).toBe(containerElementAssertion);
338+
expect(containerElementAssertion.toContainElement(text)).toBe(containerElementAssertion);
339+
expect(parentElementAssertion.toContainElement(child)).toBe(parentElementAssertion);
340+
});
341+
342+
it("throws an error for negative assertion", () => {
343+
expect(() => containerElementAssertion.not.toContainElement(parent))
344+
.toThrowError(AssertionError)
345+
.toHaveMessage("Expected element <View ... /> NOT to contain element <View ... />.");
346+
expect(() => containerElementAssertion.not.toContainElement(text))
347+
.toThrowError(AssertionError)
348+
.toHaveMessage("Expected element <View ... /> NOT to contain element <Text ... />.");
349+
});
338350
});
339351

340-
it("returns the assertion instance for negated assertions when the target element is not contained", () => {
341-
expect(parentElementAssertion.not.toContainElement(text)).toBeEqual(parentElementAssertion);
342-
expect(parentElementAssertion.not.toContainElement(container)).toBeEqual(parentElementAssertion);
352+
context("and the target element is NOT found in the children's element", () => {
353+
it("throws an error", () => {
354+
expect(() => parentElementAssertion.toContainElement(text))
355+
.toThrowError(AssertionError)
356+
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />.");
357+
});
358+
359+
it("returns the assertion instance for negative assertion", () => {
360+
expect(parentElementAssertion.not.toContainElement(text)).toBeEqual(parentElementAssertion);
361+
expect(parentElementAssertion.not.toContainElement(container)).toBeEqual(parentElementAssertion);
362+
});
343363
});
344364
});
345365

346-
context("when the container element does NOT contain the target element", () => {
366+
context("when the element does NOT have children", () => {
347367
it("throws an error", () => {
348-
expect(() => containerElementAssertion.not.toContainElement(parent))
349-
.toThrowError(AssertionError)
350-
.toHaveMessage("Expected element <View ... /> NOT to contain element <View ... />.");
351-
expect(() => containerElementAssertion.not.toContainElement(text))
352-
.toThrowError(AssertionError)
353-
.toHaveMessage("Expected element <View ... /> NOT to contain element <Text ... />.");
354-
expect(() => parentElementAssertion.toContainElement(text))
368+
expect(() => textElementAssertion.toContainElement(parent))
355369
.toThrowError(AssertionError)
356-
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />.");
370+
.toHaveMessage("Expected element <Text ... /> to contain element <View ... />.");
357371
});
358372
});
359373
});

0 commit comments

Comments
 (0)