refactor: monorepo+pnpm (removed husky)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import debounce from "../debounce"
|
||||
|
||||
describe("debounce", () => {
|
||||
test("doesn't call function right after calling", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
|
||||
expect(fn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("calls the function after the given timeout", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
jest.useFakeTimers()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalled()
|
||||
// expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 100)
|
||||
})
|
||||
|
||||
test("calls the function only one time within the timeframe", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
const debFunc = debounce(fn, 1000)
|
||||
|
||||
for (let i = 0; i < 100; i++) debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user