Skip to content

Instantly share code, notes, and snippets.

@ridoansaleh
Last active November 21, 2019 01:38
Show Gist options
  • Save ridoansaleh/4986f68e600f209ea2637124553f0608 to your computer and use it in GitHub Desktop.
Save ridoansaleh/4986f68e600f209ea2637124553f0608 to your computer and use it in GitHub Desktop.
1. AppProvider.test.js
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import AppProvider from "./AppProvider";
describe("<AppProvider />", () => {
let container = null;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
unmountComponentAtNode(container);
container.remove();
container = null;
});
it("contains props children", async () => {
await act(async () => {
render(
<AppProvider children={<p className="main">Hello World</p>} />,
container
);
});
expect(container.querySelector(".main").textContent).toBe("Hello World");
});
});
2. App.test.js
import React from "react";
import { shallow } from "enzyme";
import App from "./App";
describe("<App/> ", () => {
it("renders", () => {
shallow(<App />);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment