Skip to content

Instantly share code, notes, and snippets.

@ghengeveld
Created August 28, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghengeveld/eff5d494b35a84a6cbd5b5e66e4f0ca5 to your computer and use it in GitHub Desktop.
Save ghengeveld/eff5d494b35a84a6cbd5b5e66e4f0ca5 to your computer and use it in GitHub Desktop.
Promise test with Jest
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