From c2514debf05dc46a1f3ee9da7bb4e27d4ea4fde9 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 15 Nov 2022 18:58:07 +0300 Subject: [PATCH] Adding test for FormActions --- .../Asset/Edit/FormActions.test.tsx | 15 ++++++++++ .../Asset/Edit/FormEditMetadata.test.tsx | 30 ++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/components/Asset/Edit/FormActions.test.tsx diff --git a/src/components/Asset/Edit/FormActions.test.tsx b/src/components/Asset/Edit/FormActions.test.tsx new file mode 100644 index 000000000..0f3899d7b --- /dev/null +++ b/src/components/Asset/Edit/FormActions.test.tsx @@ -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() + expect(screen.getByText('Submit')).toBeInTheDocument() + }) +}) diff --git a/src/components/Asset/Edit/FormEditMetadata.test.tsx b/src/components/Asset/Edit/FormEditMetadata.test.tsx index 0d64e605f..0cf9441b1 100644 --- a/src/components/Asset/Edit/FormEditMetadata.test.tsx +++ b/src/components/Asset/Edit/FormEditMetadata.test.tsx @@ -1,22 +1,32 @@ import { render, screen } from '@testing-library/react' import React from 'react' -import Formik, { useFormikContext } from 'formik' +import Formik, { FormikErrors, FormikTouched, FormikState } from 'formik' import FormEditMetadata from './FormEditMetadata' 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', () => { - const useFormikContextMock = jest.spyOn(Formik, 'useFormikContext') + // const useFormikContextMock = jest.spyOn(Formik, 'useFormikContext') it('renders fixed price', () => { - // render() - // (useFormikContext as jest.Mock). - // + fieldMock = { foo: 'bar' } + render( + + ) expect(screen.getByText('New Title')).toBeInTheDocument() }) })