Created
November 19, 2020 22:59
-
-
Save jepser/822943aefe40af3d64120317f1c9411f to your computer and use it in GitHub Desktop.
Talo example test
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 { 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