import { act, create } from "react-test-renderer";
import Script from "../script";
describe("Script", () => {
test("should not render a script tag without code or src", () => {
let root;
act(() => {
root = create();
});
// This is here to make sure the virtual dom tree does not return anything.
expect(root.toJSON()).toMatchInlineSnapshot(`null`);
expect(document.body.querySelector("#script-1")).toBeNull();
});
test("should render a script tag with src", () => {
act(() => {
create();
});
expect(document.body.querySelector("#script-2")).toMatchInlineSnapshot(`
`);
});
test("should not render the passed children with src", () => {
act(() => {
create(
);
});
expect(document.body.querySelector("#script-3")).toMatchInlineSnapshot(`
`);
});
test("should execute the code", () => {
act(() => {
create();
});
expect(document.body.querySelector("#script-4")).toBeNull();
expect(global["__i__"]).toEqual(Infinity);
});
test("should remove the script tag at unmount", () => {
let root;
act(() => {
root = create();
});
expect(document.body.querySelector("#script-5")).toMatchInlineSnapshot(`
`);
act(() => {
root.unmount();
});
expect(document.body.querySelector("#script-5")).toBeNull();
});
});