-
Notifications
You must be signed in to change notification settings - Fork 2
feat(native): Add toContainElement() #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f7871e3
b8c2020
0ff3dab
9655a2f
bce26e2
5d763e2
f75daf5
5c7300b
d93e39c
b8d0042
8328f48
cbe8895
84baa60
795446d
a560a05
b0c7b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,4 +311,64 @@ describe("[Unit] ElementAssertion.test.ts", () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe (".toContainElement", () => { | ||
const element = render( | ||
Comment on lines
+315
to
+316
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a good practice, elements should be rendered on each test |
||
<View testID="grandParentId"> | ||
<View testID="parentId"> | ||
<View testID="childId" /> | ||
</View> | ||
<Text testID="textId" /> | ||
</View>, | ||
Comment on lines
+317
to
+322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im trying to do this, but im not getting good results, would you like to pair? |
||
); | ||
|
||
const container = element.getByTestId("grandParentId"); | ||
const containerElementAssertion = new ElementAssertion(container); | ||
const parent = element.getByTestId("parentId"); | ||
const parentElementAssertion = new ElementAssertion(parent); | ||
const child = element.getByTestId("childId"); | ||
const text = element.getByTestId("textId"); | ||
const textElementAssertion = new ElementAssertion(text); | ||
|
||
context("when the element has children", () => { | ||
context("and the target element is found in the children's element", () => { | ||
it("returns the assertion instance", () => { | ||
expect(containerElementAssertion.toContainElement(parent)).toBe(containerElementAssertion); | ||
expect(containerElementAssertion.toContainElement(child)).toBe(containerElementAssertion); | ||
expect(containerElementAssertion.toContainElement(text)).toBe(containerElementAssertion); | ||
expect(parentElementAssertion.toContainElement(child)).toBe(parentElementAssertion); | ||
}); | ||
|
||
it("throws an error for negative assertion", () => { | ||
expect(() => containerElementAssertion.not.toContainElement(parent)) | ||
.toThrowError(AssertionError) | ||
.toHaveMessage("Expected element <View ... /> NOT to contain element <View ... />."); | ||
expect(() => containerElementAssertion.not.toContainElement(text)) | ||
.toThrowError(AssertionError) | ||
.toHaveMessage("Expected element <View ... /> NOT to contain element <Text ... />."); | ||
}); | ||
}); | ||
|
||
context("and the target element is NOT found in the children's element", () => { | ||
it("throws an error", () => { | ||
expect(() => parentElementAssertion.toContainElement(text)) | ||
.toThrowError(AssertionError) | ||
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />."); | ||
}); | ||
|
||
it("returns the assertion instance for negative assertion", () => { | ||
expect(parentElementAssertion.not.toContainElement(text)).toBeEqual(parentElementAssertion); | ||
expect(parentElementAssertion.not.toContainElement(container)).toBeEqual(parentElementAssertion); | ||
}); | ||
}); | ||
}); | ||
|
||
context("when the element does NOT have children", () => { | ||
it("throws an error", () => { | ||
expect(() => textElementAssertion.toContainElement(parent)) | ||
.toThrowError(AssertionError) | ||
.toHaveMessage("Expected element <Text ... /> to contain element <View ... />."); | ||
}); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we please add some tests for when there are no child nor parent elements 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the recommendation! To take this into account, I've changed the structure of the tests so they're clearer and easier to read 🚀 |
||
}); |
Uh oh!
There was an error while loading. Please reload this page.