mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
make Jest run
This commit is contained in:
parent
4aa885ff4f
commit
829ec502a2
1
src/@types/node_modules.d.ts
vendored
Normal file
1
src/@types/node_modules.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare module 'intersection-observer'
|
@ -1,9 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import testRender from '../../tests/unit/testRender'
|
|
||||||
import Layout from './Layout'
|
|
||||||
|
|
||||||
describe('Layout', () => {
|
|
||||||
testRender(
|
|
||||||
<Layout location={{ href: 'https://demo.com' } as Location}>Hello</Layout>
|
|
||||||
)
|
|
||||||
})
|
|
@ -1,14 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import testRender from './testRender'
|
||||||
import Layout from '../../src/Layout'
|
import Layout from '../../src/components/Layout'
|
||||||
|
|
||||||
describe('Layout', () => {
|
describe('Layout', () => {
|
||||||
it('renders without crashing', () => {
|
testRender(
|
||||||
const { container } = render(
|
<Layout location={{ href: 'https://demo.com' } as Location}>Hello</Layout>
|
||||||
<Layout title="Hello" description="Hello">
|
)
|
||||||
Hello
|
|
||||||
</Layout>
|
|
||||||
)
|
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createMocks } from 'node-mocks-http'
|
import { createMocks } from 'node-mocks-http'
|
||||||
import apiRoute from '../../../src/pages/api/file'
|
import apiRoute from '../../../api/file'
|
||||||
|
|
||||||
describe('/api/file', () => {
|
describe('/api/file', () => {
|
||||||
test('responds 405 to GET', async () => {
|
test('responds 405 to GET', async () => {
|
||||||
|
@ -4,7 +4,9 @@ import Button from '../../../src/components/atoms/Button'
|
|||||||
|
|
||||||
describe('Button', () => {
|
describe('Button', () => {
|
||||||
it('primary renders correctly', () => {
|
it('primary renders correctly', () => {
|
||||||
const { container } = render(<Button primary>I am a primary button</Button>)
|
const { container } = render(
|
||||||
|
<Button style="primary">I am a primary button</Button>
|
||||||
|
)
|
||||||
|
|
||||||
const button = container.querySelector('button')
|
const button = container.querySelector('button')
|
||||||
expect(button).toBeInTheDocument()
|
expect(button).toBeInTheDocument()
|
||||||
@ -21,12 +23,14 @@ describe('Button', () => {
|
|||||||
expect(button).toHaveTextContent('href')
|
expect(button).toHaveTextContent('href')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('link renders correctly without crashing', () => {
|
it('text renders correctly without crashing', () => {
|
||||||
const { container } = render(<Button link>I am a link button</Button>)
|
const { container } = render(
|
||||||
|
<Button style="text">I am a text button</Button>
|
||||||
|
)
|
||||||
|
|
||||||
const button = container.querySelector('button')
|
const button = container.querySelector('button')
|
||||||
expect(button).toBeInTheDocument()
|
expect(button).toBeInTheDocument()
|
||||||
expect(button).toHaveTextContent('link')
|
expect(button).toHaveTextContent('text')
|
||||||
expect(button && button.className).toMatch(/link/)
|
expect(button && button.className).toMatch(/text/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render, act } from '@testing-library/react'
|
||||||
import DateRangeWidget, {
|
import DateRangeWidget, {
|
||||||
getWidgetValue
|
getWidgetValue
|
||||||
} from '../../../src/components/atoms/FormWidgets/DateRangeWidget'
|
} from '../../../src/components/atoms/FormWidgets/DateRangeWidget'
|
||||||
import { PublishFormSchema } from '../../../src/models/PublishForm'
|
import { PublishFormSchema } from '../../../src/models/PublishForm'
|
||||||
import { act } from 'react-test-renderer'
|
|
||||||
|
|
||||||
describe('Date Range Widget', () => {
|
describe('Date Range Widget', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { render } from '@testing-library/react'
|
|
||||||
import NProgress from '../../../src/components/atoms/NProgress'
|
|
||||||
|
|
||||||
describe('NProgress', () => {
|
|
||||||
it('nprogress options can be passed', () => {
|
|
||||||
const { container } = render(<NProgress options={{ minimum: 2 } as any} />)
|
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,13 +1,16 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
rootDir: '../../',
|
rootDir: '../../',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.[jt]sx?$': ['babel-jest', { configFile: './jest/babel.config.js' }]
|
'^.+\\.[jt]sx?$': [
|
||||||
|
'babel-jest',
|
||||||
|
{ configFile: './tests/unit/babel.config.js' }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
|
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
|
||||||
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
||||||
'<rootDir>/tests/unit/__mocks__/file-mock.js',
|
'<rootDir>/tests/unit/__mocks__/fileMock.js',
|
||||||
'\\.svg': '<rootDir>/tests/unit/__mocks__/svgr-mock.js'
|
'\\.svg': '<rootDir>/tests/unit/__mocks__/svgrMock.js'
|
||||||
},
|
},
|
||||||
testPathIgnorePatterns: ['node_modules', '.cache', 'public', 'coverage'],
|
testPathIgnorePatterns: ['node_modules', '.cache', 'public', 'coverage'],
|
||||||
transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'],
|
transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'],
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render, fireEvent } from '@testing-library/react'
|
import { render, fireEvent } from '@testing-library/react'
|
||||||
import { NextPageContext } from 'next'
|
|
||||||
import Search from '../../../src/pages/search'
|
import Search from '../../../src/pages/search'
|
||||||
import ddo from '../__fixtures__/ddo'
|
import ddo from '../__fixtures__/ddo'
|
||||||
import { DDO } from '@oceanprotocol/squid'
|
import { DDO } from '@oceanprotocol/squid'
|
||||||
@ -55,26 +54,3 @@ describe('Search', () => {
|
|||||||
expect(container.querySelector('.empty')).toBeInTheDocument()
|
expect(container.querySelector('.empty')).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Search.getInitialProps', () => {
|
|
||||||
it('returns the corresponding props', async () => {
|
|
||||||
const getInitialProps = Search.getInitialProps as (
|
|
||||||
context: Partial<NextPageContext>
|
|
||||||
) => {
|
|
||||||
text: string
|
|
||||||
tag: string
|
|
||||||
queryResult: QueryResult
|
|
||||||
}
|
|
||||||
const context = {
|
|
||||||
query: {
|
|
||||||
text: 'text',
|
|
||||||
tag: 'tag',
|
|
||||||
page: '1',
|
|
||||||
offset: '1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const props = await getInitialProps(context)
|
|
||||||
expect(props.text).toEqual('text')
|
|
||||||
expect(props.tag).toEqual('tag')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import axios, { AxiosResponse } from 'axios'
|
import axios, { AxiosResponse } from 'axios'
|
||||||
import { mocked } from 'ts-jest/dist/util/testing'
|
|
||||||
import getAssetRating, {
|
import getAssetRating, {
|
||||||
GetRatingResponse
|
GetRatingResponse
|
||||||
} from '../../../src/utils/getAssetRating'
|
} from '../../../src/utils/getAssetRating'
|
||||||
@ -13,7 +12,8 @@ describe('getAssetRating()', () => {
|
|||||||
datePublished: '',
|
datePublished: '',
|
||||||
vote: 5
|
vote: 5
|
||||||
}
|
}
|
||||||
mocked(axios.get).mockResolvedValueOnce({
|
|
||||||
|
;(axios.get as any).mockResolvedValueOnce({
|
||||||
data: [ratingResponse, ratingResponse]
|
data: [ratingResponse, ratingResponse]
|
||||||
} as AxiosResponse)
|
} as AxiosResponse)
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import axios, { AxiosResponse } from 'axios'
|
import axios, { AxiosResponse } from 'axios'
|
||||||
import { mocked } from 'ts-jest/dist/util/testing'
|
|
||||||
import getFromFaucet from '../../../src/utils/getFromFaucet'
|
import getFromFaucet from '../../../src/utils/getFromFaucet'
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
|
|
||||||
describe('getFromFaucet()', () => {
|
describe('getFromFaucet()', () => {
|
||||||
mocked(axios).mockResolvedValue({
|
;(axios as any).mockResolvedValue({
|
||||||
data: { success: true, message: 'hello' }
|
data: { success: true, message: 'hello' }
|
||||||
} as AxiosResponse)
|
} as AxiosResponse)
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import axios, { AxiosResponse } from 'axios'
|
import axios, { AxiosResponse } from 'axios'
|
||||||
import { mocked } from 'ts-jest/dist/util/testing'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
toStringNoMS,
|
toStringNoMS,
|
||||||
@ -34,7 +33,7 @@ describe('toStringNoMS()', () => {
|
|||||||
|
|
||||||
describe('getFileInfo()', () => {
|
describe('getFileInfo()', () => {
|
||||||
it('Success on existing file', async () => {
|
it('Success on existing file', async () => {
|
||||||
mocked(axios).mockResolvedValue({
|
;(axios as any).mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
status: 200,
|
status: 200,
|
||||||
result: { contentLength: '10000', contentType: 'application/pdf' }
|
result: { contentLength: '10000', contentType: 'application/pdf' }
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import axios, { AxiosResponse } from 'axios'
|
import axios, { AxiosResponse } from 'axios'
|
||||||
import { mocked } from 'ts-jest/dist/util/testing'
|
|
||||||
import rateAsset, { RatingResponse } from '../../../src/utils/rateAsset'
|
import rateAsset, { RatingResponse } from '../../../src/utils/rateAsset'
|
||||||
import web3 from '../__mocks__/web3'
|
import web3 from '../__mocks__/web3'
|
||||||
|
|
||||||
@ -7,7 +6,7 @@ jest.mock('axios')
|
|||||||
|
|
||||||
describe('rateAsset()', () => {
|
describe('rateAsset()', () => {
|
||||||
it('success', async () => {
|
it('success', async () => {
|
||||||
mocked(axios.post).mockResolvedValueOnce({
|
;(axios.post as any).mockResolvedValueOnce({
|
||||||
data: ['4.0', 1]
|
data: ['4.0', 1]
|
||||||
} as AxiosResponse)
|
} as AxiosResponse)
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ describe('rateAsset()', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('string return', async () => {
|
it('string return', async () => {
|
||||||
mocked(axios.post).mockResolvedValueOnce({
|
;(axios.post as any).mockResolvedValueOnce({
|
||||||
data: 'Missing signature'
|
data: 'Missing signature'
|
||||||
} as AxiosResponse)
|
} as AxiosResponse)
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ describe('rateAsset()', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('error catch', async () => {
|
it('error catch', async () => {
|
||||||
mocked(axios.post).mockResolvedValueOnce({
|
;(axios.post as any).mockResolvedValueOnce({
|
||||||
data: {}
|
data: {}
|
||||||
} as AxiosResponse)
|
} as AxiosResponse)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user