-
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(switch): convert tests to RTL - FE-6634 #6965
Conversation
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.
Nice work on this @DipperTheDan! 👍🏼 Just so you are aware it appears the old switch.spec.tsx
file still exists after these changes. Would you be able to remove it please?
src/components/switch/__internal__/switch-slider-panel.test.tsx
Outdated
Show resolved
Hide resolved
9cbd215
to
a10bce3
Compare
}, | ||
}} | ||
> | ||
<Switch checked onChange={jest.fn()} /> |
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.
nit-pick: not sure if this was missed but we could also just use a no-op function here
<Switch checked onChange={jest.fn()} /> | |
<Switch checked onChange={() => {}} /> |
}, | ||
}} | ||
> | ||
<Switch onChange={jest.fn()} /> |
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.
Same here
<Switch onChange={jest.fn()} /> | |
<Switch onChange={() => {}} /> |
expect(hintTextWrapper).toHaveStyleRule("margin-bottom: var(--spacing000)"); | ||
}); | ||
|
||
test("the expected translations are correctly applied", () => { |
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.
nit-pick (non-blocking): think we could add a bit more detail to more easily differentiate this test from the next
test("the expected translations are correctly applied", () => { | |
test("the expected translations are correctly applied for on", () => { |
expect(i18nText[0]).toBeVisible(); | ||
}); | ||
|
||
it("can use i18n for off", () => { |
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.
nit-pick (non-blocking): and also amend this description for consistency
it("can use i18n for off", () => { | |
test("the expected translations are correctly applied for off", () => { |
test("renders the expected hint text when `labelHelp` is a string value", () => { | ||
render( | ||
<CarbonProvider validationRedesignOptIn> | ||
<Switch label="foo" labelHelp="hint text" warning="this is a warning" /> | ||
</CarbonProvider> | ||
); | ||
|
||
expect(screen.getByTestId("hint-text")).toBeVisible(); | ||
}); |
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): Aware that this is for coverage so happy for this to be left as it is however, I think we could slightly amend the description to make it a bit more clear what is being tested. I also think we could also just assert that the text is visible instead of using the test-id here
test("renders the expected hint text when `labelHelp` is a string value", () => { | |
render( | |
<CarbonProvider validationRedesignOptIn> | |
<Switch label="foo" labelHelp="hint text" warning="this is a warning" /> | |
</CarbonProvider> | |
); | |
expect(screen.getByTestId("hint-text")).toBeVisible(); | |
}); | |
test("renders `labelHelp` as hint text when `validationRedesignOptIn` flag is true", () => { | |
render( | |
<CarbonProvider validationRedesignOptIn> | |
<Switch label="foo" labelHelp="hint text" warning="this is a warning" /> | |
</CarbonProvider> | |
); | |
expect(screen.getByText("hint text")).toBeVisible(); | |
}); |
730854c
to
8e0b590
Compare
🎉 This PR is included in version 142.11.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Proposed behaviour
Unit tests should use RTL
Current behaviour
Unit tests use Enzyme
Checklist
d.ts
file added or updated if requiredQA
Additional context
N/A
Testing instructions
N/A