From 2416d17b74d63b7ee45ce4557bca51f96dee7ce1 Mon Sep 17 00:00:00 2001 From: shao Date: Wed, 14 Aug 2019 18:07:38 +0800 Subject: [PATCH] test: reduce test time --- components/anchor/__tests__/Anchor.test.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/components/anchor/__tests__/Anchor.test.js b/components/anchor/__tests__/Anchor.test.js index c263ca58f6..3ddd087dbb 100644 --- a/components/anchor/__tests__/Anchor.test.js +++ b/components/anchor/__tests__/Anchor.test.js @@ -276,10 +276,16 @@ describe('Anchor Render', () => { it('Anchor targetOffset prop', async () => { jest.useFakeTimers(); - const dateNowMock = jest - .spyOn(Date, 'now') - .mockImplementationOnce(() => 0) - .mockImplementationOnce(() => 1000); + let dateNowMock; + + function dataNowMockFn() { + return jest + .spyOn(Date, 'now') + .mockImplementationOnce(() => 0) + .mockImplementationOnce(() => 1000); + } + + dateNowMock = dataNowMockFn(); const scrollToSpy = jest.spyOn(window, 'scrollTo'); let root = document.getElementById('root'); @@ -297,11 +303,13 @@ describe('Anchor Render', () => { wrapper.instance().handleScrollTo('#API'); jest.runAllTimers(); expect(scrollToSpy).toHaveBeenLastCalledWith(0, 1000); + dateNowMock = dataNowMockFn(); wrapper.setProps({ offsetTop: 100 }); wrapper.instance().handleScrollTo('#API'); jest.runAllTimers(); expect(scrollToSpy).toHaveBeenLastCalledWith(0, 900); + dateNowMock = dataNowMockFn(); wrapper.setProps({ targetOffset: 200 }); wrapper.instance().handleScrollTo('#API');