Skip to content

Commit edae9a7

Browse files
[Security Packages] Migrate low-complexity Enzyme test to React Testing Library (#253842)
## Summary Migrated 1 test file in **@kbn/security-form-components** from Enzyme to React Testing Library. __Related: https://github.com/elastic/kibana/issues/223148__ --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f767c17 commit edae9a7

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

x-pack/platform/packages/shared/security/form_components/src/form_row.test.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@
66
*/
77

88
import { EuiFormRow } from '@elastic/eui';
9-
import { mount } from 'enzyme';
9+
import { render } from '@testing-library/react';
1010
import { Formik } from 'formik';
1111
import React from 'react';
1212

1313
import { FormRow } from './form_row';
1414

15+
jest.mock('@elastic/eui', () => {
16+
const actual = jest.requireActual('@elastic/eui');
17+
return {
18+
...actual,
19+
EuiFormRow: jest.fn(({ children }: any) => <div>{children}</div>),
20+
};
21+
});
22+
23+
const MockedEuiFormRow = EuiFormRow as unknown as jest.Mock;
24+
1525
describe('FormRow', () => {
1626
it('should render form row with correct error states', () => {
1727
const assertions = [
@@ -20,7 +30,9 @@ describe('FormRow', () => {
2030
{ error: undefined, touched: true, isInvalid: false },
2131
];
2232
assertions.forEach(({ error, touched, isInvalid }) => {
23-
const wrapper = mount(
33+
MockedEuiFormRow.mockClear();
34+
35+
render(
2436
<Formik
2537
onSubmit={jest.fn()}
2638
initialValues={{ email: '' }}
@@ -33,11 +45,12 @@ describe('FormRow', () => {
3345
</Formik>
3446
);
3547

36-
expect(wrapper.find(EuiFormRow).props()).toEqual(
48+
expect(MockedEuiFormRow).toHaveBeenCalledWith(
3749
expect.objectContaining({
3850
error,
3951
isInvalid,
40-
})
52+
}),
53+
expect.anything()
4154
);
4255
});
4356
});

x-pack/platform/packages/shared/security/form_components/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"jest",
77
"node",
88
"react",
9+
"@testing-library/jest-dom",
910
"@kbn/ambient-ui-types",
1011
"@testing-library/jest-dom",
1112
]

0 commit comments

Comments
 (0)