1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-13 16:54:53 +01:00

make Jest run

This commit is contained in:
Matthias Kretschmann 2020-06-30 14:19:27 +02:00
parent 4aa885ff4f
commit 829ec502a2
Signed by: m
GPG Key ID: 606EEEF3C479A91F
13 changed files with 30 additions and 74 deletions

1
src/@types/node_modules.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module 'intersection-observer'

View File

@ -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>
)
})

View File

@ -1,14 +1,9 @@
import React from 'react'
import { render } from '@testing-library/react'
import Layout from '../../src/Layout'
import testRender from './testRender'
import Layout from '../../src/components/Layout'
describe('Layout', () => {
it('renders without crashing', () => {
const { container } = render(
<Layout title="Hello" description="Hello">
Hello
</Layout>
)
expect(container.firstChild).toBeInTheDocument()
})
testRender(
<Layout location={{ href: 'https://demo.com' } as Location}>Hello</Layout>
)
})

View File

@ -1,5 +1,5 @@
import { createMocks } from 'node-mocks-http'
import apiRoute from '../../../src/pages/api/file'
import apiRoute from '../../../api/file'
describe('/api/file', () => {
test('responds 405 to GET', async () => {

View File

@ -4,7 +4,9 @@ import Button from '../../../src/components/atoms/Button'
describe('Button', () => {
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')
expect(button).toBeInTheDocument()
@ -21,12 +23,14 @@ describe('Button', () => {
expect(button).toHaveTextContent('href')
})
it('link renders correctly without crashing', () => {
const { container } = render(<Button link>I am a link button</Button>)
it('text renders correctly without crashing', () => {
const { container } = render(
<Button style="text">I am a text button</Button>
)
const button = container.querySelector('button')
expect(button).toBeInTheDocument()
expect(button).toHaveTextContent('link')
expect(button && button.className).toMatch(/link/)
expect(button).toHaveTextContent('text')
expect(button && button.className).toMatch(/text/)
})
})

View File

@ -1,10 +1,9 @@
import React from 'react'
import { render } from '@testing-library/react'
import { render, act } from '@testing-library/react'
import DateRangeWidget, {
getWidgetValue
} from '../../../src/components/atoms/FormWidgets/DateRangeWidget'
import { PublishFormSchema } from '../../../src/models/PublishForm'
import { act } from 'react-test-renderer'
describe('Date Range Widget', () => {
it('renders without crashing', () => {

View File

@ -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()
})
})

View File

@ -1,13 +1,16 @@
module.exports = {
rootDir: '../../',
transform: {
'^.+\\.[jt]sx?$': ['babel-jest', { configFile: './jest/babel.config.js' }]
'^.+\\.[jt]sx?$': [
'babel-jest',
{ configFile: './tests/unit/babel.config.js' }
]
},
moduleNameMapper: {
'.+\\.(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)$':
'<rootDir>/tests/unit/__mocks__/file-mock.js',
'\\.svg': '<rootDir>/tests/unit/__mocks__/svgr-mock.js'
'<rootDir>/tests/unit/__mocks__/fileMock.js',
'\\.svg': '<rootDir>/tests/unit/__mocks__/svgrMock.js'
},
testPathIgnorePatterns: ['node_modules', '.cache', 'public', 'coverage'],
transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'],

View File

@ -1,6 +1,5 @@
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import { NextPageContext } from 'next'
import Search from '../../../src/pages/search'
import ddo from '../__fixtures__/ddo'
import { DDO } from '@oceanprotocol/squid'
@ -55,26 +54,3 @@ describe('Search', () => {
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')
})
})

View File

@ -1,5 +1,4 @@
import axios, { AxiosResponse } from 'axios'
import { mocked } from 'ts-jest/dist/util/testing'
import getAssetRating, {
GetRatingResponse
} from '../../../src/utils/getAssetRating'
@ -13,7 +12,8 @@ describe('getAssetRating()', () => {
datePublished: '',
vote: 5
}
mocked(axios.get).mockResolvedValueOnce({
;(axios.get as any).mockResolvedValueOnce({
data: [ratingResponse, ratingResponse]
} as AxiosResponse)

View File

@ -1,11 +1,10 @@
import axios, { AxiosResponse } from 'axios'
import { mocked } from 'ts-jest/dist/util/testing'
import getFromFaucet from '../../../src/utils/getFromFaucet'
jest.mock('axios')
describe('getFromFaucet()', () => {
mocked(axios).mockResolvedValue({
;(axios as any).mockResolvedValue({
data: { success: true, message: 'hello' }
} as AxiosResponse)

View File

@ -1,5 +1,4 @@
import axios, { AxiosResponse } from 'axios'
import { mocked } from 'ts-jest/dist/util/testing'
import {
toStringNoMS,
@ -34,7 +33,7 @@ describe('toStringNoMS()', () => {
describe('getFileInfo()', () => {
it('Success on existing file', async () => {
mocked(axios).mockResolvedValue({
;(axios as any).mockResolvedValue({
data: {
status: 200,
result: { contentLength: '10000', contentType: 'application/pdf' }

View File

@ -1,5 +1,4 @@
import axios, { AxiosResponse } from 'axios'
import { mocked } from 'ts-jest/dist/util/testing'
import rateAsset, { RatingResponse } from '../../../src/utils/rateAsset'
import web3 from '../__mocks__/web3'
@ -7,7 +6,7 @@ jest.mock('axios')
describe('rateAsset()', () => {
it('success', async () => {
mocked(axios.post).mockResolvedValueOnce({
;(axios.post as any).mockResolvedValueOnce({
data: ['4.0', 1]
} as AxiosResponse)
@ -16,7 +15,7 @@ describe('rateAsset()', () => {
})
it('string return', async () => {
mocked(axios.post).mockResolvedValueOnce({
;(axios.post as any).mockResolvedValueOnce({
data: 'Missing signature'
} as AxiosResponse)
@ -25,7 +24,7 @@ describe('rateAsset()', () => {
})
it('error catch', async () => {
mocked(axios.post).mockResolvedValueOnce({
;(axios.post as any).mockResolvedValueOnce({
data: {}
} as AxiosResponse)