Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aneuwald-ctw committed May 8, 2024
1 parent e5f69e4 commit 960e266
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/studio-base/src/panels/createSyncRoot.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @jest-environment jsdom */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import { screen } from "@testing-library/react";
import { act } from "react-dom/test-utils";

import { createSyncRoot } from "@foxglove/studio-base/panels/createSyncRoot";

describe("createSyncRoot", () => {
it("should mount the component", async () => {
const textTest = "Mount Component Test";
const TestComponent = () => <div>{textTest}</div>;

const container = document.createElement("div");
document.body.appendChild(container);

act(() => {
createSyncRoot(<TestComponent />, container);
});

expect(await screen.findByText(textTest)).toBeDefined();
});

it("should unmount the component", async () => {
const textTest = "Unmount Component Test";
const TestComponent = () => <div>{textTest}</div>;

const container = document.createElement("div");
document.body.appendChild(container);

act(() => {
const unmountCb = createSyncRoot(<TestComponent />, container);
unmountCb();
});

expect(JSON.stringify(await screen.findByText(textTest))).toBe("{}");
});
});
4 changes: 4 additions & 0 deletions packages/studio-web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ export async function main(getParams: () => Promise<MainParams> = async () => ({
</LogAfterRender>
</StrictMode>,
);

setTimeout(() => {
root.unmount();
}, 5_000);
}

0 comments on commit 960e266

Please sign in to comment.