keycloak-scim/src/components/data-loader/__tests__/DataLoader.test.tsx

37 lines
877 B
TypeScript
Raw Normal View History

2020-09-03 17:25:35 +00:00
import React from "react";
import { DataLoader } from "../DataLoader";
2020-09-03 17:25:35 +00:00
import { act } from "@testing-library/react";
import { render, unmountComponentAtNode } from "react-dom";
let container: HTMLDivElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
unmountComponentAtNode(container);
container.remove();
});
describe("<DataLoader />", () => {
it("render", async () => {
const loader = () => Promise.resolve(["a", "b"]);
await act(async () => {
render(
<DataLoader loader={loader}>
{(result) => (
2020-09-03 17:25:35 +00:00
<div>
{result.map((d, i) => (
2020-09-03 17:25:35 +00:00
<i key={i}>{d}</i>
))}
</div>
)}
</DataLoader>,
container
);
});
expect(container.textContent).toBe("ab");
});
});