Skip to content

Commit

Permalink
refactor(test): mock performan.now
Browse files Browse the repository at this point in the history
  • Loading branch information
Aybrea committed Mar 14, 2024
1 parent d568ae4 commit b347b43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/varlet-ui/src/countdown/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ describe('test countdown methods', () => {
}

test('test countdown start method', async () => {
let callCount = 0
vi.spyOn(performance, 'now').mockImplementation(() => {
callCount += 1
return 1000 + 500 * callCount
})

const wrapper = mount(Wrapper)
await delay(0)
const text = wrapper.text()
Expand Down Expand Up @@ -131,6 +137,8 @@ describe('test countdown methods', () => {
})

test('test countdown reset method', async () => {
vi.spyOn(performance, 'now').mockReturnValue(1000)

const wrapper = mount(Wrapper)
await delay(0)
const text = wrapper.text()
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/slider/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('test slider props', () => {
await trigger(el, 'touchstart', 0, 0)
await trigger(document, 'touchmove', 50, 0)
await trigger(document, 'touchend', 50, 0)
console.log(wrapper.vm.value)

expect(wrapper.vm.value).not.toBe(0)
expect(wrapper.vm.value % 3).toBe(0)
mockRestore()
Expand Down

0 comments on commit b347b43

Please sign in to comment.