Closed
Description
Because my svelte component is being compiled to a web component I need to do some additional validation on passed in attributes within the onMount
function. If I throw an exception for an invalid attribute type the element isn't removed from the DOM and all later tests then fail due to the findByRole
method then finding more than one element.
onMount(() => {
if (!isButtonType(type)) {
throw "Invalid button type";
}
if (!isSize(size)) {
throw "Invalid button size";
}
if (!isVariant(variant)) {
throw "Invalid button variant";
}
})
describe("size", () => {
["compact", "foo"].forEach(size => {
it(`should render ${size} size`, async () => {
const { findByRole } = render(GoAButton, { size });
const button = await findByRole("button");
expect(button).toBeTruthy();
expect(button.className).toContain(size);
});
});
});
I have tried calling the cleanup
method in an afterEach
, but that didn't change anything.