Browse Source

test: reduce test time

pull/17827/head
shao 5 years ago
parent
commit
2416d17b74
  1. 16
      components/anchor/__tests__/Anchor.test.js

16
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');

Loading…
Cancel
Save