aotds-docks/src/routes/(editor)/export/Serialized.test.js

35 lines
962 B
JavaScript
Raw Normal View History

2023-05-16 19:00:54 +00:00
import { fireEvent, render, waitFor } from "@testing-library/svelte";
2023-04-24 15:54:56 +00:00
import "@testing-library/jest-dom";
2023-05-16 19:00:54 +00:00
import { vi } from "vitest";
import userEvent from "@testing-library/user-event";
import { tick } from "svelte";
2023-04-24 15:54:56 +00:00
import Serialized from "./Serialized.svelte";
test("basic", () => {
const { getByText } = render(Serialized, {
props: {
2023-05-08 20:07:16 +00:00
data: { greeting: "hello world" },
2023-04-24 15:54:56 +00:00
},
});
2023-05-08 20:07:16 +00:00
waitFor(() => expect(getByText("hello world")).toBeInTheDocument());
2023-04-24 15:54:56 +00:00
});
2023-05-16 19:00:54 +00:00
test("clipboard", async () => {
const { getByText } = render(Serialized, {
props: {
data: { a: 1 },
},
});
await tick();
userEvent.setup();
const write = vi.spyOn(navigator.clipboard, "writeText");
await fireEvent.click(getByText("clipboard"));
expect(navigator.clipboard.writeText).not.toHaveBeenCalledWith({ a: 1 });
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(`{\n "a": 1\n}`);
});