Skip to content

Commit 59f2303

Browse files
authored
[FEQ]/Jim/FEQ-1628/add unit tests for payment method field (#13400)
* chore: add test cases for payment method field * chore: add white space * chore: update selector
1 parent 1779ab7 commit 59f2303

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { useForm } from 'react-hook-form';
3+
import { render, screen } from '@testing-library/react';
4+
import PaymentMethodField from '../PaymentMethodField';
5+
6+
jest.mock('react-hook-form', () => ({
7+
...jest.requireActual('react-hook-form'),
8+
Controller: ({ control, defaultValue, name, render }) =>
9+
render({
10+
field: { control, name, onBlur: jest.fn(), onChange: jest.fn(), value: defaultValue },
11+
fieldState: { error: null },
12+
}),
13+
useForm: () => ({
14+
control: 'mockedControl',
15+
}),
16+
}));
17+
18+
const mockUseForm = useForm as jest.MockedFunction<typeof useForm>;
19+
20+
describe('PaymentMethodField', () => {
21+
const { control } = mockUseForm();
22+
it('should render a textarea when the field prop is set to instructions', () => {
23+
render(<PaymentMethodField control={control} defaultValue='' displayName='textarea' field='instructions' />);
24+
expect(screen.getByText('textarea')).toBeInTheDocument();
25+
});
26+
it('should render an input when the field prop is set to text', () => {
27+
render(<PaymentMethodField control={control} defaultValue='' displayName='input' field='text' required />);
28+
expect(screen.getByPlaceholderText('input')).toBeInTheDocument();
29+
});
30+
});

0 commit comments

Comments
 (0)