Skip to content

Commit

Permalink
test: use rc-test (react-component#848)
Browse files Browse the repository at this point in the history
* test: use rc-test

* test: bump deps
  • Loading branch information
zombieJ authored Oct 21, 2022
1 parent 46a4072 commit eefb3e9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
17 changes: 9 additions & 8 deletions .fatherrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export default {
cjs: 'babel',
esm: { type: 'babel', importLibToEs: true },
preCommit: {
eslint: true,
prettier: true,
import { defineConfig } from 'father';

export default defineConfig({
platform: 'browser',
cjs: { output: 'lib' },
esm: {
output: 'es',
alias: { 'rc-util/lib': 'rc-util/es' },
},
runtimeHelpers: true,
};
});
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"compile": "father build",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
"test": "father test",
"test": "rc-test",
"tsc": "tsc --noEmit",
"now-build": "npm run build"
},
Expand Down Expand Up @@ -63,11 +63,12 @@
"enzyme": "^3.3.0",
"enzyme-to-json": "^3.4.0",
"eslint": "^7.1.0",
"father": "^2.13.2",
"father": "^4.0.0",
"jsonp": "^0.2.1",
"np": "^7.5.0",
"prettier": "^2.7.1",
"rc-dialog": "^9.0.0",
"rc-test": "^7.0.9",
"typescript": "^4.2.3"
}
}
}
12 changes: 8 additions & 4 deletions tests/Hooks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render } from '@testing-library/react';
import useLock from '../src/hooks/useLock';
import { injectRunAllTimers } from './utils/common';

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

it('useLock', () => {
jest.useFakeTimers();
const clearTimeoutSpy = jest.spyOn(window, 'clearTimeout');

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

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

const wrapper = mount(<Component />);
const { unmount } = render(<Component />);

clearTimeoutSpy.mockReset();
outSetLock(true);
wrapper.unmount();
unmount();

expect(window.clearTimeout).toHaveBeenCalled();
expect(clearTimeoutSpy).toHaveBeenCalled();

clearTimeoutSpy.mockRestore();

jest.runAllTimers();
jest.useRealTimers();
Expand Down
13 changes: 8 additions & 5 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mount, render } from 'enzyme';
import { render as testingRender, fireEvent } from '@testing-library/react';
import KeyCode from 'rc-util/lib/KeyCode';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import { resetWarned } from 'rc-util/lib/warning';
Expand Down Expand Up @@ -1151,7 +1152,7 @@ describe('Select.Basic', () => {

const onChildClick = jest.fn();
const onMouseDown = jest.fn();
const wrapper = mount(
const { container } = testingRender(
<Select
onMouseDown={onMouseDown}
dropdownRender={(menu) => (
Expand All @@ -1168,17 +1169,19 @@ describe('Select.Basic', () => {
</Select>,
);

toggleOpen(wrapper);
wrapper.find('div#dropdown-custom-node').simulate('mousedown');
wrapper.find('div#dropdown-custom-node').simulate('click');
// Open
fireEvent.mouseDown(container.querySelector('.rc-select-selector'));

fireEvent.mouseDown(container.querySelector('div#dropdown-custom-node'));
fireEvent.click(container.querySelector('div#dropdown-custom-node'));
expect(onMouseDown).toHaveBeenCalled();
expect(onChildClick).toHaveBeenCalled();

document.body.focus();

jest.runAllTimers();

expect(wrapper.find('input').instance()).toBe(document.activeElement);
expect(container.querySelector('input')).toBe(document.activeElement);

jest.useRealTimers();
});
Expand Down

0 comments on commit eefb3e9

Please sign in to comment.