Created
August 28, 2019 20:55
-
-
Save ghengeveld/eff5d494b35a84a6cbd5b5e66e4f0ca5 to your computer and use it in GitHub Desktop.
Promise test with Jest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { render, unmountComponentAtNode } from "react-dom" | |
import { act } from "react-dom/test-utils" | |
let container = null | |
beforeEach(() => { | |
// setup a DOM element as a render target | |
container = document.createElement("div") | |
document.body.appendChild(container) | |
}) | |
afterEach(() => { | |
// cleanup on exiting | |
unmountComponentAtNode(container) | |
container.remove() | |
container = null | |
}) | |
const Hello = () => { | |
const promise = Promise.reject("Oh no!") | |
return <div>Hello world</div> | |
} | |
test("HelloWorld", () => { | |
act(() => { | |
render(<Hello />, container) | |
}) | |
expect(container.textContent).toBe("Hello world") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment