Skip to content

Commit c66a961

Browse files
committed
unit: more tests for Form.tsx
1 parent 9d4dcf7 commit c66a961

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/__tests__/Form.spec.tsx

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
1+
// Library
2+
import React from 'react';
3+
import { mount } from 'enzyme';
4+
5+
// Internal
6+
import Form from '../Form';
7+
18
describe('Form', () => {
2-
it('Test it works well', () => {
3-
expect(true).toBe(true);
9+
it('Mount the form with basic fields', () => {
10+
const path = 'name';
11+
const onChange = jest.fn(() => 'onChangeFunc');
12+
const schema = {
13+
'type': 'string',
14+
'title': 'First Name',
15+
};
16+
17+
const uiSchema = {
18+
};
19+
20+
const data = 'Bob';
21+
22+
// act
23+
const wrapper = mount(
24+
<Form
25+
schema={schema}
26+
uiSchema={uiSchema}
27+
formData={data}
28+
prefixId={'test'}
29+
onChange={({ formData }) => jest.fn(formData)}
30+
onSubmit={(submittedData) => jest.fn(submittedData)}
31+
/>,
32+
);
33+
34+
// check
35+
expect(wrapper).toHaveLength(1);
36+
});
37+
38+
39+
it('Mount the form with basic fields (with error)', () => {
40+
const path = 'name';
41+
const onChange = jest.fn(() => 'onChangeFunc');
42+
const schema = {
43+
'type': 'string',
44+
'title': 'First Name',
45+
};
46+
47+
const uiSchema = {
48+
};
49+
50+
const data = 1;
51+
52+
// act
53+
const wrapper = mount(
54+
<Form
55+
schema={schema}
56+
uiSchema={uiSchema}
57+
formData={data}
58+
prefixId={'test'}
59+
onChange={({ formData }) => jest.fn(formData)}
60+
onSubmit={(submittedData) => jest.fn(submittedData)}
61+
/>,
62+
);
63+
64+
// check
65+
expect(wrapper).toHaveLength(1);
466
});
567
});

0 commit comments

Comments
 (0)