Skip to content

Instantly share code, notes, and snippets.

@jepser
Created November 19, 2020 22:59
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 jepser/822943aefe40af3d64120317f1c9411f to your computer and use it in GitHub Desktop.
Save jepser/822943aefe40af3d64120317f1c9411f to your computer and use it in GitHub Desktop.
Talo example test
import { getSuperThing } from '~/api'
const Talo = () => {
const [data, setData] = useState(null)
useEffect(() => {
getSuperThing().then(setData)
}, [])
if(!data) return null
return <OtherComponent data={data} />
}
// test
import { getSuperThing } from '~/api'
import OtherComponent from '~/components/other-component'
const serverDataMock = [{
}]
jest.mock('~/api', () => ({
getSuperThing: jest.fn(() => Promise.resolve(serverDataMock))
}))
describe('Talo', () => {
it('should getSuperThing in the first render', () => {
act(async () => {
await renderComponent(<Talo />)
})
expect(getSuperThing).toBeCalledOnce()
})
it('it should pass the correct props', () => {
let render;
act(async () => {
render = await renderComponent(<Talo />)
})
const otherComponent = render.find(OtherComponent)
expect(otherComponent).props('data').toEqual({ talo: true })
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment