Skip to content

Commit eefb3e9

Browse files
authored
test: use rc-test (#848)
* test: use rc-test * test: bump deps
1 parent 46a4072 commit eefb3e9

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

.fatherrc.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
export default {
2-
cjs: 'babel',
3-
esm: { type: 'babel', importLibToEs: true },
4-
preCommit: {
5-
eslint: true,
6-
prettier: true,
1+
import { defineConfig } from 'father';
2+
3+
export default defineConfig({
4+
platform: 'browser',
5+
cjs: { output: 'lib' },
6+
esm: {
7+
output: 'es',
8+
alias: { 'rc-util/lib': 'rc-util/es' },
79
},
8-
runtimeHelpers: true,
9-
};
10+
});

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"compile": "father build",
3636
"prepublishOnly": "npm run compile && np --yolo --no-publish",
3737
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
38-
"test": "father test",
38+
"test": "rc-test",
3939
"tsc": "tsc --noEmit",
4040
"now-build": "npm run build"
4141
},
@@ -63,11 +63,12 @@
6363
"enzyme": "^3.3.0",
6464
"enzyme-to-json": "^3.4.0",
6565
"eslint": "^7.1.0",
66-
"father": "^2.13.2",
66+
"father": "^4.0.0",
6767
"jsonp": "^0.2.1",
6868
"np": "^7.5.0",
6969
"prettier": "^2.7.1",
7070
"rc-dialog": "^9.0.0",
71+
"rc-test": "^7.0.9",
7172
"typescript": "^4.2.3"
7273
}
73-
}
74+
}

tests/Hooks.test.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { render } from '@testing-library/react';
33
import useLock from '../src/hooks/useLock';
44
import { injectRunAllTimers } from './utils/common';
55

@@ -8,6 +8,7 @@ describe('Hooks', () => {
88

99
it('useLock', () => {
1010
jest.useFakeTimers();
11+
const clearTimeoutSpy = jest.spyOn(window, 'clearTimeout');
1112

1213
let outSetLock: (newLock: boolean) => void;
1314

@@ -17,12 +18,15 @@ describe('Hooks', () => {
1718
return null;
1819
};
1920

20-
const wrapper = mount(<Component />);
21+
const { unmount } = render(<Component />);
2122

23+
clearTimeoutSpy.mockReset();
2224
outSetLock(true);
23-
wrapper.unmount();
25+
unmount();
2426

25-
expect(window.clearTimeout).toHaveBeenCalled();
27+
expect(clearTimeoutSpy).toHaveBeenCalled();
28+
29+
clearTimeoutSpy.mockRestore();
2630

2731
jest.runAllTimers();
2832
jest.useRealTimers();

tests/Select.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mount, render } from 'enzyme';
2+
import { render as testingRender, fireEvent } from '@testing-library/react';
23
import KeyCode from 'rc-util/lib/KeyCode';
34
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
45
import { resetWarned } from 'rc-util/lib/warning';
@@ -1151,7 +1152,7 @@ describe('Select.Basic', () => {
11511152

11521153
const onChildClick = jest.fn();
11531154
const onMouseDown = jest.fn();
1154-
const wrapper = mount(
1155+
const { container } = testingRender(
11551156
<Select
11561157
onMouseDown={onMouseDown}
11571158
dropdownRender={(menu) => (
@@ -1168,17 +1169,19 @@ describe('Select.Basic', () => {
11681169
</Select>,
11691170
);
11701171

1171-
toggleOpen(wrapper);
1172-
wrapper.find('div#dropdown-custom-node').simulate('mousedown');
1173-
wrapper.find('div#dropdown-custom-node').simulate('click');
1172+
// Open
1173+
fireEvent.mouseDown(container.querySelector('.rc-select-selector'));
1174+
1175+
fireEvent.mouseDown(container.querySelector('div#dropdown-custom-node'));
1176+
fireEvent.click(container.querySelector('div#dropdown-custom-node'));
11741177
expect(onMouseDown).toHaveBeenCalled();
11751178
expect(onChildClick).toHaveBeenCalled();
11761179

11771180
document.body.focus();
11781181

11791182
jest.runAllTimers();
11801183

1181-
expect(wrapper.find('input').instance()).toBe(document.activeElement);
1184+
expect(container.querySelector('input')).toBe(document.activeElement);
11821185

11831186
jest.useRealTimers();
11841187
});

0 commit comments

Comments
 (0)