1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/client/src/hooks/use-ipfs.test.tsx
Matthias Kretschmann 9daa49a085
fix async unit tests
* async act() to the rescue with React 16.9+
2019-10-30 10:58:30 +01:00

28 lines
716 B
TypeScript

import React from 'react'
import { render, wait, act } from '@testing-library/react'
import useIpfs from './use-ipfs'
export default function TestComponent() {
const { ipfsVersion, isIpfsReady, ipfsError, ipfsMessage } = useIpfs()
return (
<div>
{isIpfsReady && <span>Ready</span>}
{ipfsVersion} - {ipfsMessage} - {ipfsError}
</div>
)
}
describe('use-ipfs', () => {
it('renders without crashing', async () => {
let element: any
await act(async () => {
element = render(<TestComponent />)
})
expect(element.container.firstChild).toBeInTheDocument()
await wait(() => element.getByText('Ready'))
})
})