1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Adding test for FormActions

This commit is contained in:
Jamie Hewitt 2022-11-15 18:58:07 +03:00
parent 6776ffe34d
commit c2514debf0
2 changed files with 35 additions and 10 deletions

View File

@ -0,0 +1,15 @@
import { render, screen } from '@testing-library/react'
import React from 'react'
import { useFormikContext } from 'formik'
import FormActions from './FormActions'
jest.mock('formik')
describe('src/components/Asset/Edit/FormActions.tsx', () => {
it('renders fixed price', () => {
const isValid = true
;(useFormikContext as jest.Mock).mockReturnValue([isValid])
render(<FormActions />)
expect(screen.getByText('Submit')).toBeInTheDocument()
})
})

View File

@ -1,22 +1,32 @@
import { render, screen } from '@testing-library/react' import { render, screen } from '@testing-library/react'
import React from 'react' import React from 'react'
import Formik, { useFormikContext } from 'formik' import Formik, { FormikErrors, FormikTouched, FormikState } from 'formik'
import FormEditMetadata from './FormEditMetadata' import FormEditMetadata from './FormEditMetadata'
import content from '../../../../content/pages/editMetadata.json' import content from '../../../../content/pages/editMetadata.json'
jest.mock('formik') let fieldMock = {}
const metaMock = {}
const helperMock = {}
jest.mock('formik', () => ({
...jest.requireActual('formik'),
useField: jest.fn(() => {
return [fieldMock, metaMock, helperMock]
})
}))
describe('src/components/Asset/Edit/FormEditMetadata.tsx', () => { describe('src/components/Asset/Edit/FormEditMetadata.tsx', () => {
const useFormikContextMock = jest.spyOn(Formik, 'useFormikContext') // const useFormikContextMock = jest.spyOn(Formik, 'useFormikContext')
it('renders fixed price', () => { it('renders fixed price', () => {
// render() fieldMock = { foo: 'bar' }
// (useFormikContext as jest.Mock). render(
// <FormEditMetadata <FormEditMetadata
// data={content.form.data} data={content.form.data}
// showPrice={true} showPrice={true}
// isComputeDataset={false} isComputeDataset={false}
// /> />
)
expect(screen.getByText('New Title')).toBeInTheDocument() expect(screen.getByText('New Title')).toBeInTheDocument()
}) })
}) })