1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

unit test fixes

This commit is contained in:
Matthias Kretschmann 2019-09-05 12:03:14 +02:00
parent b6d255bbad
commit 5002effbfe
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 55 additions and 2 deletions

View File

@ -35,7 +35,7 @@ export default function useIpfs() {
ipfsMessage = message ipfsMessage = message
console.error(message) console.error(message)
ipfs = null ipfs = null
setIpfsInitError(error) setIpfsInitError(error.message)
} }
} }
setIpfsReady(Boolean(ipfs)) setIpfsReady(Boolean(ipfs))

View File

@ -0,0 +1,15 @@
import React from 'react'
import { render } from '@testing-library/react'
import Ipfs from './Ipfs'
const addFile = jest.fn()
describe('Ipfs', () => {
it('renders without crashing', async () => {
const { container, findByText } = render(<Ipfs addFile={addFile} />)
expect(container.firstChild).toBeInTheDocument()
// wait for IPFS node
await findByText(/IPFS /)
})
})

View File

@ -5,6 +5,22 @@ import Files from '.'
const onChange = jest.fn() const onChange = jest.fn()
// filter out IPFS node messages
const originalLog = console.log
beforeAll(() => {
console.log = (...args: any) => {
if (/Swarm listening/.test(args[0])) {
return
}
originalLog.call(console, ...args)
}
})
afterAll(() => {
console.log = originalLog
})
afterEach(() => { afterEach(() => {
mockAxios.reset() mockAxios.reset()
}) })
@ -67,13 +83,16 @@ describe('Files', () => {
}) })
it('new IPFS file form can be opened and closed', async () => { it('new IPFS file form can be opened and closed', async () => {
const { container, getByText } = renderComponent() const { container, getByText, findByText } = renderComponent()
// open // open
fireEvent.click(getByText('+ Add to IPFS')) fireEvent.click(getByText('+ Add to IPFS'))
await waitForElement(() => getByText('- Cancel')) await waitForElement(() => getByText('- Cancel'))
expect(container.querySelector('.ipfsForm')).toBeInTheDocument() expect(container.querySelector('.ipfsForm')).toBeInTheDocument()
// wait for IPFS node
await findByText(/IPFS /)
// close // close
fireEvent.click(getByText('- Cancel')) fireEvent.click(getByText('- Cancel'))
await waitForElement(() => getByText('+ Add to IPFS')) await waitForElement(() => getByText('+ Add to IPFS'))

View File

@ -1,2 +1,21 @@
/* eslint-disable no-console */
import '@testing-library/jest-dom/extend-expect' import '@testing-library/jest-dom/extend-expect'
import '@testing-library/react/cleanup-after-each' import '@testing-library/react/cleanup-after-each'
// this is just a little hack to silence a warning that we'll get until we
// upgrade to 16.9: https://github.com/facebook/react/pull/14853
const originalError = console.error
beforeAll(() => {
console.error = (...args) => {
if (/Warning.*not wrapped in act/.test(args[0])) {
return
}
originalError.call(console, ...args)
}
})
afterAll(() => {
console.error = originalError
})