diff --git a/components/back-top/__tests__/index.test.js b/components/back-top/__tests__/index.test.js
index 3c835ab1de..0eebccbe7b 100644
--- a/components/back-top/__tests__/index.test.js
+++ b/components/back-top/__tests__/index.test.js
@@ -2,17 +2,23 @@ import React from 'react';
import { mount } from 'enzyme';
import BackTop from '..';
-const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
-
describe('BackTop', () => {
- it('should scroll to top after click it', async () => {
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+
+ afterAll(() => {
+ jest.useRealTimers();
+ });
+
+ it('should scroll to top after click it', () => {
const wrapper = mount();
document.documentElement.scrollTop = 400;
// trigger scroll manually
wrapper.node.handleScroll();
- await delay(500);
+ jest.runAllTimers();
wrapper.find('.ant-back-top').simulate('click');
- await delay(500);
+ jest.runAllTimers();
expect(Math.round(document.documentElement.scrollTop)).toBe(0);
});
});
diff --git a/components/card/__tests__/index.test.js b/components/card/__tests__/index.test.js
index a4e72031f3..98bae0d936 100644
--- a/components/card/__tests__/index.test.js
+++ b/components/card/__tests__/index.test.js
@@ -2,10 +2,17 @@ import React from 'react';
import { mount } from 'enzyme';
import Card from '../index';
-const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
const testMethod = typeof window !== 'undefined' ? it : xit;
describe('Card', () => {
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+
+ afterAll(() => {
+ jest.useRealTimers();
+ });
+
function fakeResizeWindowTo(wrapper, width) {
Object.defineProperties(wrapper.node.container, {
offsetWidth: {
@@ -16,13 +23,13 @@ describe('Card', () => {
window.resizeTo(width);
}
- testMethod('resize card will trigger different padding', async () => {
+ testMethod('resize card will trigger different padding', () => {
const wrapper = mount(xxx);
fakeResizeWindowTo(wrapper, 1000);
- await delay(0);
+ jest.runAllTimers();
expect(wrapper.hasClass('ant-card-wider-padding')).toBe(true);
fakeResizeWindowTo(wrapper, 800);
- await delay(0);
+ jest.runAllTimers();
expect(wrapper.hasClass('ant-card-wider-padding')).toBe(false);
});
});
diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js
index 43341a4d73..065affcb4f 100644
--- a/components/input/__tests__/index.test.js
+++ b/components/input/__tests__/index.test.js
@@ -5,10 +5,8 @@ import Form from '../../form';
const { TextArea } = Input;
-const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
-
describe('Input', () => {
- it('should support maxLength', async () => {
+ it('should support maxLength', () => {
const wrapper = mount(
);
@@ -17,27 +15,35 @@ describe('Input', () => {
});
describe('TextArea', () => {
- it('should auto calculate height according to content length', async () => {
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+
+ afterAll(() => {
+ jest.useRealTimers();
+ });
+
+ it('should auto calculate height according to content length', () => {
const wrapper = mount(
);
const mockFunc = jest.spyOn(wrapper.node, 'resizeTextarea');
wrapper.setProps({ value: '1111\n2222\n3333' });
- await delay(0);
+ jest.runAllTimers();
expect(mockFunc).toHaveBeenCalledTimes(1);
wrapper.setProps({ value: '1111' });
- await delay(0);
+ jest.runAllTimers();
expect(mockFunc).toHaveBeenCalledTimes(2);
});
- it('should support disabled', async () => {
+ it('should support disabled', () => {
const wrapper = mount(
);
expect(wrapper).toMatchSnapshot();
});
- it('should support maxLength', async () => {
+ it('should support maxLength', () => {
const wrapper = mount(
);
@@ -46,7 +52,7 @@ describe('TextArea', () => {
});
describe('As Form Control', () => {
- it('should be reset when wrapped in form.getFieldDecorator without initialValue', async () => {
+ it('should be reset when wrapped in form.getFieldDecorator without initialValue', () => {
class Demo extends React.Component {
reset = () => {
this.props.form.resetFields();
@@ -79,7 +85,7 @@ describe('As Form Control', () => {
});
describe('Input.Search', () => {
- it('should support suffix', async () => {
+ it('should support suffix', () => {
const wrapper = mount(
);
diff --git a/components/menu/__tests__/index.test.js b/components/menu/__tests__/index.test.js
index f4b42848f5..9d8fd69dec 100644
--- a/components/menu/__tests__/index.test.js
+++ b/components/menu/__tests__/index.test.js
@@ -4,9 +4,16 @@ import Menu from '..';
import Icon from '../../icon';
const { SubMenu } = Menu;
-const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
describe('Menu', () => {
+ beforeEach(() => {
+ jest.useFakeTimers();
+ });
+
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
it('should accept defaultOpenKeys in mode horizontal', () => {
const wrapper = mount(