Skip to content

Commit 392d9c6

Browse files
kdquistanchalalopenchi
authored andcommitted
(CR): Address Code Review comments
1 parent b2afbfa commit 392d9c6

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
@@ -330,32 +330,46 @@ describe("[Unit] ElementAssertion.test.ts", () => {
330330
const parentElementAssertion = new ElementAssertion(parent);
331331
const child = element.getByTestId("childId");
332332
const text = element.getByTestId("textId");
333+
const textElementAssertion = new ElementAssertion(text);
333334

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

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

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

0 commit comments

Comments
 (0)