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(