|
1 | 1 | import React from 'react'; |
2 | | -import { render, screen, act } from '@testing-library/react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
3 | 3 | import userEvent from '@testing-library/user-event'; |
4 | 4 |
|
5 | 5 | import FormRenderer from '../../form-renderer'; |
@@ -84,68 +84,62 @@ describe('FormRenderer validator', () => { |
84 | 84 | }); |
85 | 85 |
|
86 | 86 | it('should convert object validator to warning', async () => { |
87 | | - await act(async () => { |
88 | | - render( |
89 | | - <FormRenderer |
90 | | - FormTemplate={FormTemplate} |
91 | | - componentMapper={{ |
92 | | - [componentTypes.TEXT_FIELD]: TextFieldWarning, |
93 | | - }} |
94 | | - schema={{ |
95 | | - fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [{ type: 'required', warning: true }] }], |
96 | | - }} |
97 | | - onSubmit={jest.fn()} |
98 | | - /> |
99 | | - ); |
100 | | - }); |
101 | | - |
102 | | - expect(screen.getByText('Required')).toBeInTheDocument(); |
| 87 | + render( |
| 88 | + <FormRenderer |
| 89 | + FormTemplate={FormTemplate} |
| 90 | + componentMapper={{ |
| 91 | + [componentTypes.TEXT_FIELD]: TextFieldWarning, |
| 92 | + }} |
| 93 | + schema={{ |
| 94 | + fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [{ type: 'required', warning: true }] }], |
| 95 | + }} |
| 96 | + onSubmit={jest.fn()} |
| 97 | + /> |
| 98 | + ); |
| 99 | + |
| 100 | + expect(await screen.findByText('Required')).toBeInTheDocument(); |
103 | 101 | }); |
104 | 102 |
|
105 | 103 | it('should convert function validator to warning', async () => { |
106 | 104 | const ERROR = 'SOME-ERROR'; |
107 | 105 |
|
108 | 106 | const customValidator = () => ({ type: 'warning', error: ERROR }); |
109 | 107 |
|
110 | | - await act(async () => { |
111 | | - render( |
112 | | - <FormRenderer |
113 | | - FormTemplate={FormTemplate} |
114 | | - componentMapper={{ |
115 | | - [componentTypes.TEXT_FIELD]: TextFieldWarning, |
116 | | - }} |
117 | | - schema={{ |
118 | | - fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [customValidator] }], |
119 | | - }} |
120 | | - onSubmit={jest.fn()} |
121 | | - /> |
122 | | - ); |
123 | | - }); |
124 | | - |
125 | | - expect(screen.getByText(ERROR)).toBeInTheDocument(); |
| 108 | + render( |
| 109 | + <FormRenderer |
| 110 | + FormTemplate={FormTemplate} |
| 111 | + componentMapper={{ |
| 112 | + [componentTypes.TEXT_FIELD]: TextFieldWarning, |
| 113 | + }} |
| 114 | + schema={{ |
| 115 | + fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [customValidator] }], |
| 116 | + }} |
| 117 | + onSubmit={jest.fn()} |
| 118 | + /> |
| 119 | + ); |
| 120 | + |
| 121 | + expect(await screen.findByText(ERROR)).toBeInTheDocument(); |
126 | 122 | }); |
127 | 123 |
|
128 | 124 | it('should convert async function validator to warning', async () => { |
129 | 125 | const ERROR = 'SOME-ERROR'; |
130 | 126 |
|
131 | 127 | const customValidator = () => new Promise((res, rej) => setTimeout(() => rej({ type: 'warning', error: ERROR }))); |
132 | 128 |
|
133 | | - await act(async () => { |
134 | | - render( |
135 | | - <FormRenderer |
136 | | - FormTemplate={FormTemplate} |
137 | | - componentMapper={{ |
138 | | - [componentTypes.TEXT_FIELD]: TextFieldWarning, |
139 | | - }} |
140 | | - schema={{ |
141 | | - fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [customValidator] }], |
142 | | - }} |
143 | | - onSubmit={jest.fn()} |
144 | | - /> |
145 | | - ); |
146 | | - }); |
147 | | - |
148 | | - expect(screen.getByText(ERROR)).toBeInTheDocument(); |
| 129 | + render( |
| 130 | + <FormRenderer |
| 131 | + FormTemplate={FormTemplate} |
| 132 | + componentMapper={{ |
| 133 | + [componentTypes.TEXT_FIELD]: TextFieldWarning, |
| 134 | + }} |
| 135 | + schema={{ |
| 136 | + fields: [{ useWarnings: true, component: 'text-field', name: NAME, validate: [customValidator] }], |
| 137 | + }} |
| 138 | + onSubmit={jest.fn()} |
| 139 | + /> |
| 140 | + ); |
| 141 | + |
| 142 | + expect(await screen.findByText(ERROR)).toBeInTheDocument(); |
149 | 143 | }); |
150 | 144 | }); |
151 | 145 | }); |
0 commit comments