diff --git a/components/auto-complete/__tests__/__snapshots__/index.test.js.snap b/components/auto-complete/__tests__/__snapshots__/index.test.js.snap
deleted file mode 100644
index d4791da902..0000000000
--- a/components/auto-complete/__tests__/__snapshots__/index.test.js.snap
+++ /dev/null
@@ -1,121 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`AutoComplete legacy dataSource should accept react element option 1`] = `
-
-`;
-
-exports[`AutoComplete rtl render component should be rendered correctly in RTL direction 1`] = `
-
-`;
diff --git a/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap b/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap
new file mode 100644
index 0000000000..3105d49829
--- /dev/null
+++ b/components/auto-complete/__tests__/__snapshots__/index.test.tsx.snap
@@ -0,0 +1,32 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`AutoComplete rtl render component should be rendered correctly in RTL direction 1`] = `
+
+`;
diff --git a/components/auto-complete/__tests__/index.test.js b/components/auto-complete/__tests__/index.test.tsx
similarity index 53%
rename from components/auto-complete/__tests__/index.test.js
rename to components/auto-complete/__tests__/index.test.tsx
index 7686e70722..2c48bb8339 100644
--- a/components/auto-complete/__tests__/index.test.js
+++ b/components/auto-complete/__tests__/index.test.tsx
@@ -1,30 +1,35 @@
import React from 'react';
+import userEvent from '@testing-library/user-event';
import AutoComplete from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
-import { fireEvent, render } from '../../../tests/utils';
+import { render, screen } from '../../../tests/utils';
import Input from '../../input';
describe('AutoComplete', () => {
mountTest(AutoComplete);
rtlTest(AutoComplete);
- it('AutoComplete with custom Input render perfectly', () => {
- const { container } = render(
+ it('AutoComplete with custom Input render perfectly', async () => {
+ render(
,
);
- expect(container.querySelectorAll('textarea').length).toBe(1);
- fireEvent.change(container.querySelector('textarea'), { target: { value: '123' } });
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+
+ // should show options when type in input
+ await userEvent.type(screen.getByRole('combobox'), '123');
- // should not filter data source defaultly
- expect(container.querySelectorAll('.ant-select-item-option').length).toBe(3);
+ // should not filter data source by default
+ expect(screen.getByTitle('12345')).toBeInTheDocument();
+ expect(screen.getByTitle('23456')).toBeInTheDocument();
+ expect(screen.getByTitle('34567')).toBeInTheDocument();
});
- it('AutoComplete should work when dataSource is object array', () => {
- const { container } = render(
+ it('AutoComplete should work when dataSource is object array', async () => {
+ render(
{
,
);
- expect(container.querySelectorAll('input').length).toBe(1);
- fireEvent.change(container.querySelector('input'), { target: { value: 'a' } });
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ await userEvent.type(screen.getByRole('combobox'), 'a');
- // should not filter data source defaultly
- expect(container.querySelectorAll('.ant-select-item-option').length).toBe(2);
+ // should not filter data source by default
+ expect(screen.getByTitle('text')).toBeInTheDocument();
+ expect(screen.getByTitle('abc')).toBeInTheDocument();
});
it('AutoComplete throws error when contains invalid dataSource', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
render(
+ // @ts-ignore
{}]}>
,
@@ -54,22 +61,23 @@ describe('AutoComplete', () => {
});
it('legacy dataSource should accept react element option', () => {
- const { asFragment } = render(
- ReactNode]} />,
- );
- expect(asFragment().firstChild).toMatchSnapshot();
+ render(ReactNode]} />);
+
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ expect(screen.getByTitle(/reactnode/i)).toBeInTheDocument();
});
- it('legacy AutoComplete.Option should be compatiable', () => {
- const { container } = render(
+ it('legacy AutoComplete.Option should be compatiable', async () => {
+ render(
111
222
,
);
- expect(container.querySelectorAll('input').length).toBe(1);
- fireEvent.change(container.querySelector('input'), { target: { value: '1' } });
- expect(container.querySelectorAll('.ant-select-item-option').length).toBe(2);
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ await userEvent.type(screen.getByRole('combobox'), '1');
+ expect(screen.getByTitle(/111/i)).toBeInTheDocument();
+ expect(screen.getByTitle(/222/i)).toBeInTheDocument();
});
it('should not warning when getInputElement is null', () => {
@@ -77,16 +85,17 @@ describe('AutoComplete', () => {
render();
// eslint-disable-next-line no-console
expect(console.warn).not.toBeCalled();
+ // @ts-ignore
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('should not override custom input className', () => {
- const { container } = render(
+ render(
,
);
- expect(container.querySelector('input').classList.contains('custom')).toBeTruthy();
+ expect(screen.getByRole('combobox')).toHaveClass('custom');
});
});
diff --git a/package.json b/package.json
index ad1249f3ae..5983d16412 100644
--- a/package.json
+++ b/package.json
@@ -119,6 +119,7 @@
"@ant-design/react-slick": "~0.29.1",
"@babel/runtime": "^7.18.3",
"@ctrl/tinycolor": "^3.4.0",
+ "@testing-library/user-event": "^14.4.2",
"classnames": "^2.2.6",
"copy-to-clipboard": "^3.2.0",
"lodash": "^4.17.21",