-
Notifications
You must be signed in to change notification settings - Fork 86
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
refactor(label): convert enzyme tests to RTL #6936
Conversation
expect(screen.getByText("foo")).toHaveAttribute("id", "baz"); | ||
}); | ||
|
||
test("renders with provided `aria-label`", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(non-blocking): how about this small wording tweak to better describe both the intended behaviour and the specific prop being tested?
test("renders with provided `aria-label`", () => { | |
test("uses `aria-label` prop as its accessible name when passed", () => { |
const user = userEvent.setup(); | ||
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating"); | ||
render( | ||
<Label inline {...{ [validationProp]: "Message" }}> | ||
foo | ||
</Label> | ||
); | ||
|
||
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | ||
|
||
expect(useFloatingSpy).toHaveBeenCalledWith( | ||
expect.objectContaining({ placement: "top" }) | ||
); | ||
|
||
useFloatingSpy.mockRestore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: what do you think of this modification to check the data-placement
attribute on the tooltip? This would avoid the need to mock @floating-ui/react-dom:
const user = userEvent.setup(); | |
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating"); | |
render( | |
<Label inline {...{ [validationProp]: "Message" }}> | |
foo | |
</Label> | |
); | |
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | |
expect(useFloatingSpy).toHaveBeenCalledWith( | |
expect.objectContaining({ placement: "top" }) | |
); | |
useFloatingSpy.mockRestore(); | |
const user = userEvent.setup(); | |
render( | |
<Label inline {...{ [validationProp]: "Message" }}> | |
foo | |
</Label> | |
); | |
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | |
expect(await screen.findByRole("tooltip")).toHaveAttribute("data-placement", "top"); |
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating"); | ||
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>); | ||
|
||
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | ||
|
||
expect(useFloatingSpy).toHaveBeenCalledWith( | ||
expect.objectContaining({ placement: "right" }) | ||
); | ||
|
||
useFloatingSpy.mockRestore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Similar to the previous test, what do you think about this change? It would avoid the need to mock @floating-ui/react-dom:
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating"); | |
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>); | |
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | |
expect(useFloatingSpy).toHaveBeenCalledWith( | |
expect.objectContaining({ placement: "right" }) | |
); | |
useFloatingSpy.mockRestore(); | |
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>); | |
await user.hover(screen.getByTestId(`icon-${validationProp}`)); | |
expect(await screen.findByRole("tooltip")).toHaveAttribute("data-placement", "right"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing more to add from me. Just address the comments left by @Parsium 😄
bd3bf74
to
ef3b8e0
Compare
🎉 This PR is included in version 142.9.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Proposed behaviour
Convert tests to RTL
Remove unreachable branch
Current behaviour
Tests are in enzyme
Checklist
d.ts
file added or updated if requiredQA
Additional context
Testing instructions