Skip to content

Commit

Permalink
test: test order
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Feb 18, 2024
1 parent 23a3524 commit 0d5b88a
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions src/test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,54 +86,6 @@ describe('compute positions', () => {
})
})

describe('debounce', () => {
jest.useFakeTimers()

const func = jest.fn()

test('execute just once', () => {
const debouncedFunc = debounce(func, 1000)
for (let i = 0; i < 100; i += 1) {
debouncedFunc()
}

expect(func).not.toHaveBeenCalled()

jest.runAllTimers()

expect(func).toBeCalledTimes(1)
})

test('execute immediately just once', () => {
const debouncedFunc = debounce(func, 1000, true)

debouncedFunc()
expect(func).toBeCalledTimes(1)

for (let i = 0; i < 100; i += 1) {
debouncedFunc()
}

jest.runAllTimers()

expect(func).toHaveBeenCalledTimes(1)
})

test('does not execute after cancel', () => {
const debouncedFunc = debounce(func, 1000)

debouncedFunc()

expect(func).not.toHaveBeenCalled()

debouncedFunc.cancel()

jest.runAllTimers()

expect(func).not.toHaveBeenCalled()
})
})

describe('css supports', () => {
let windowSpy

Expand Down Expand Up @@ -183,3 +135,51 @@ describe('css time to ms', () => {
expect(cssTimeToMs('1000')).toBe(0)
})
})

describe('debounce', () => {
jest.useFakeTimers()

const func = jest.fn()

test('execute just once', () => {
const debouncedFunc = debounce(func, 1000)
for (let i = 0; i < 100; i += 1) {
debouncedFunc()
}

expect(func).not.toHaveBeenCalled()

jest.runAllTimers()

expect(func).toBeCalledTimes(1)
})

test('execute immediately just once', () => {
const debouncedFunc = debounce(func, 1000, true)

debouncedFunc()
expect(func).toBeCalledTimes(1)

for (let i = 0; i < 100; i += 1) {
debouncedFunc()
}

jest.runAllTimers()

expect(func).toHaveBeenCalledTimes(1)
})

test('does not execute after cancel', () => {
const debouncedFunc = debounce(func, 1000)

debouncedFunc()

expect(func).not.toHaveBeenCalled()

debouncedFunc.cancel()

jest.runAllTimers()

expect(func).not.toHaveBeenCalled()
})
})

0 comments on commit 0d5b88a

Please sign in to comment.