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:
parent
b6d255bbad
commit
5002effbfe
@ -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))
|
||||||
|
15
client/src/routes/Publish/Files/Ipfs.test.tsx
Normal file
15
client/src/routes/Publish/Files/Ipfs.test.tsx
Normal 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 /)
|
||||||
|
})
|
||||||
|
})
|
@ -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'))
|
||||||
|
@ -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
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user