Skip to content

Failed tests don't remove element from DOM #190

Closed
@chrisolsen

Description

@chrisolsen

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);
      });
    });
  });

Errors raised
image

I have tried calling the cleanup method in an afterEach, but that didn't change anything.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions