Skip to content

Instantly share code, notes, and snippets.

@ghengeveld
Created August 28, 2019 20:55
Show Gist options
  • Select an option

  • Save ghengeveld/eff5d494b35a84a6cbd5b5e66e4f0ca5 to your computer and use it in GitHub Desktop.

Select an option

Save ghengeveld/eff5d494b35a84a6cbd5b5e66e4f0ca5 to your computer and use it in GitHub Desktop.

Revisions

  1. ghengeveld created this gist Aug 28, 2019.
    30 changes: 30 additions & 0 deletions hello.spec.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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")
    })