Skip to content

Commit 1fdcb7a

Browse files
authored
test: replaced with testing lib (#1036)
* fix: update ref * test: update testcase * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * test: part of test * chore: rollback * chore: rollback * test: fix test case * test: update snapshot
1 parent 61628c5 commit 1fdcb7a

32 files changed

+1303
-1240
lines changed

jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@babel/runtime": "^7.10.1",
49-
"@rc-component/trigger": "^2.0.0",
49+
"@rc-component/trigger": "^2.1.1",
5050
"classnames": "2.x",
5151
"rc-motion": "^2.0.1",
5252
"rc-overflow": "^1.3.1",
@@ -55,17 +55,13 @@
5555
},
5656
"devDependencies": {
5757
"@testing-library/jest-dom": "^5.16.5",
58-
"@testing-library/react": "^12.1.5",
59-
"@types/enzyme": "^3.10.9",
58+
"@testing-library/react": "^13.0.0",
6059
"@types/jest": "^26.0.24",
6160
"@types/react": "^18.2.45",
6261
"@types/react-dom": "^18.2.18",
6362
"babel-jest": "^29.6.1",
6463
"cross-env": "^7.0.0",
6564
"dumi": "^2.2.13",
66-
"enzyme": "^3.3.0",
67-
"enzyme-adapter-react-16": "^1.15.7",
68-
"enzyme-to-json": "^3.4.0",
6965
"eslint": "^8.55.0",
7066
"eslint-plugin-jest": "^27.6.0",
7167
"eslint-plugin-unicorn": "^50.0.1",
@@ -77,6 +73,8 @@
7773
"querystring": "^0.2.1",
7874
"rc-dialog": "^9.0.0",
7975
"rc-test": "^7.0.9",
76+
"react": "^18.2.0",
77+
"react-dom": "^18.2.0",
8078
"typescript": "^5.2.2"
8179
}
8280
}

tests/Accessibility.test.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { mount } from 'enzyme';
21
import * as React from 'react';
32
import KeyCode from 'rc-util/lib/KeyCode';
43
import Select from '../src';
5-
import { injectRunAllTimers, expectOpen } from './utils/common';
4+
import { injectRunAllTimers, expectOpen, keyDown } from './utils/common';
5+
import { fireEvent, render } from '@testing-library/react';
66

77
describe('Select.Accessibility', () => {
88
injectRunAllTimers(jest);
@@ -17,17 +17,13 @@ describe('Select.Accessibility', () => {
1717

1818
it('pass aria info to internal input', () => {
1919
const MySelect = Select as any;
20-
const wrapper = mount(<MySelect aria-label="light" data-attr="bamboo" useless="2333" />);
21-
expect(wrapper.find('input').props()).toEqual(
22-
expect.objectContaining({
23-
'aria-label': 'light',
24-
}),
25-
);
20+
const { container } = render(<MySelect aria-label="light" data-attr="bamboo" useless="2333" />);
21+
expect(container.querySelector('input')!.getAttribute('aria-label')).toEqual('light');
2622
});
2723

2824
// https://github.com/ant-design/ant-design/issues/31850
2925
it('active index should keep', () => {
30-
const wrapper = mount(
26+
const { container } = render(
3127
<Select
3228
showSearch
3329
options={[
@@ -48,25 +44,27 @@ describe('Select.Accessibility', () => {
4844
);
4945

5046
// First Match
51-
wrapper.find('input').simulate('change', { target: { value: 'b' } });
47+
fireEvent.change(container.querySelector('input')!, { target: { value: 'b' } });
5248
jest.runAllTimers();
5349

54-
expectOpen(wrapper);
50+
expectOpen(container);
5551
expect(
56-
wrapper.find('.rc-select-item-option-active .rc-select-item-option-content').text(),
52+
document.querySelector('.rc-select-item-option-active .rc-select-item-option-content')
53+
.textContent,
5754
).toEqual('Bamboo');
5855

59-
wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
60-
expectOpen(wrapper, false);
56+
keyDown(container.querySelector('input')!, KeyCode.ENTER);
57+
expectOpen(container, false);
6158

6259
// Next Match
63-
wrapper.find('input').simulate('change', { target: { value: '' } });
64-
wrapper.find('input').simulate('change', { target: { value: 'g' } });
60+
fireEvent.change(container.querySelector('input')!, { target: { value: '' } });
61+
fireEvent.change(container.querySelector('input')!, { target: { value: 'g' } });
6562
jest.runAllTimers();
6663

67-
expectOpen(wrapper);
64+
expectOpen(container);
6865
expect(
69-
wrapper.find('.rc-select-item-option-active .rc-select-item-option-content').text(),
66+
document.querySelector('.rc-select-item-option-active .rc-select-item-option-content')!
67+
.textContent,
7068
).toEqual('Light');
7169
});
7270
});

tests/BaseSelect.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OptionListProps, RefOptionListProps } from '@/OptionList';
2-
import { fireEvent, render } from '@testing-library/react';
2+
import { act, fireEvent, render } from '@testing-library/react';
33
import { forwardRef } from 'react';
44
import BaseSelect from '../src/BaseSelect';
55

@@ -34,6 +34,7 @@ describe('BaseSelect', () => {
3434
fireEvent.click(container.querySelector('a.trigger'));
3535
expect(container.querySelector('div.rc-select-dropdown-hidden')).toBeTruthy();
3636
});
37+
3738
it('customized inputElement style should includes position: absolute', () => {
3839
jest.useFakeTimers();
3940
const { container } = render(
@@ -50,7 +51,9 @@ describe('BaseSelect', () => {
5051
);
5152
expect(container.querySelector('div.rc-select')).toBeTruthy();
5253
fireEvent.focus(container.querySelector('div.rc-select'));
53-
jest.runAllTimers();
54+
act(() => {
55+
jest.runAllTimers();
56+
});
5457
expect(
5558
getComputedStyle(container.querySelector(`span[aria-live=polite]`)).getPropertyValue(
5659
'position',

0 commit comments

Comments
 (0)