Skip to content

How to use baseElement? #15

@samausir

Description

@samausir

The way I use it:

import { expect, test } from "vitest";
import { render } from "vitest-browser-svelte";
import Checkbox from "./Checkbox.svelte";

test("Checkbox check", async () => {
  const form = document.createElement("form");
  document.body.appendChild(form);

  const screen = render(
    Checkbox,
    { checked: true, name: "agreed" },
    { baseElement: form },
  );

  const formData = new FormData(form);
  expect(formData.get("agreed")).toStrictEqual("on");
});

This works fine for a single test, but as soon as I add a second test, the cleanup for the first test fails with this error:

NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

Here's a repo with the tests:
https://github.com/samausir/base-element

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions