Skip to content

Commit

Permalink
test: reduce test time
Browse files Browse the repository at this point in the history
  • Loading branch information
shaodahong committed Aug 16, 2019
1 parent 9a3feda commit 2416d17
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions components/anchor/__tests__/Anchor.test.js
Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 2416d17

Please sign in to comment.