forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEQ]/Jim/FEQ-1628/add unit tests for payment method field (deriv-com…
…#13400) * chore: add test cases for payment method field * chore: add white space * chore: update selector
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/p2p-v2/src/components/PaymentMethodField/__tests__/PaymentMethodField.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { render, screen } from '@testing-library/react'; | ||
import PaymentMethodField from '../PaymentMethodField'; | ||
|
||
jest.mock('react-hook-form', () => ({ | ||
...jest.requireActual('react-hook-form'), | ||
Controller: ({ control, defaultValue, name, render }) => | ||
render({ | ||
field: { control, name, onBlur: jest.fn(), onChange: jest.fn(), value: defaultValue }, | ||
fieldState: { error: null }, | ||
}), | ||
useForm: () => ({ | ||
control: 'mockedControl', | ||
}), | ||
})); | ||
|
||
const mockUseForm = useForm as jest.MockedFunction<typeof useForm>; | ||
|
||
describe('PaymentMethodField', () => { | ||
const { control } = mockUseForm(); | ||
it('should render a textarea when the field prop is set to instructions', () => { | ||
render(<PaymentMethodField control={control} defaultValue='' displayName='textarea' field='instructions' />); | ||
expect(screen.getByText('textarea')).toBeInTheDocument(); | ||
}); | ||
it('should render an input when the field prop is set to text', () => { | ||
render(<PaymentMethodField control={control} defaultValue='' displayName='input' field='text' required />); | ||
expect(screen.getByPlaceholderText('input')).toBeInTheDocument(); | ||
}); | ||
}); |