Skip to content

Commit

Permalink
update animationFrameUtils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Sep 20, 2024
1 parent 9ada6f2 commit df39784
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { waitFor } from '@testing-library/react'
import { type MockInstance } from 'vitest'

import {
cancelAnimationTimeout,
requestAnimationTimeout,
} from './animationFrameUtils'

describe('requestAnimationTimeout', () => {
let requestAnimationFrameSpy: jest.SpyInstance
let dateNowSpy: jest.SpyInstance
let requestAnimationFrameSpy: MockInstance
let dateNowSpy: MockInstance

beforeEach(() => {
requestAnimationFrameSpy = jest.spyOn(window, 'requestAnimationFrame')
dateNowSpy = jest.spyOn(Date, 'now')
requestAnimationFrameSpy = vi.spyOn(window, 'requestAnimationFrame')
dateNowSpy = vi.spyOn(Date, 'now')
})

afterEach(() => {
requestAnimationFrameSpy.mockReset()
dateNowSpy.mockReset()
jest.clearAllMocks()
vi.clearAllMocks()
})

it('should call the callback after the specified delay', async () => {
Expand All @@ -31,7 +32,7 @@ describe('requestAnimationTimeout', () => {
return 1
})

const callback = jest.fn()
const callback = vi.fn()
requestAnimationTimeout(callback, 1000)

await waitFor(() => expect(callback).toHaveBeenCalled())
Expand All @@ -48,7 +49,7 @@ describe('requestAnimationTimeout', () => {
return 1
})

const callback = jest.fn()
const callback = vi.fn()
requestAnimationTimeout(callback, 1000)

await waitFor(() =>
Expand All @@ -67,7 +68,7 @@ describe('requestAnimationTimeout', () => {
return 1
})

const callback = jest.fn()
const callback = vi.fn()
requestAnimationTimeout(callback, 1000)

await waitFor(() =>
Expand All @@ -77,10 +78,10 @@ describe('requestAnimationTimeout', () => {
})

describe('cancelAnimationTimeout', () => {
let cancelAnimationFrameSpy: jest.SpyInstance
let cancelAnimationFrameSpy: MockInstance

beforeEach(() => {
cancelAnimationFrameSpy = jest.spyOn(window, 'cancelAnimationFrame')
cancelAnimationFrameSpy = vi.spyOn(window, 'cancelAnimationFrame')
})

it('should call window.cancelAnimationFrame', () => {
Expand Down

0 comments on commit df39784

Please sign in to comment.