local V=require("\046\046\047\100\101\098\111\117\110\099\101")local h=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local G=h.expect local Q=h.jest local R=h.it local A=h.beforeEach local i local k A(function()k,i=Q.fn()end)R("\099\097\108\108\115 \116\104\101 \102\117\110\099\116\105\111\110 \111\110\099\101 \119\105\116\104\105\110 \097 \102\114\097\109\101",function()local h=V(1,i)h()h();(G(k)).toHaveBeenCalledTimes(1)end)R("\099\097\108\108\115 \116\104\101 \102\117\110\099\116\105\111\110 \097\103\097\105\110 \097\102\116\101\114 \116\104\101 \100\117\114\097\116\105\111\110 \104\097\115 \112\097\115\115\101\100",function()local h=V(0,i)h()task.wait()h();(G(k)).toHaveBeenCalledTimes(2)end)
local debounce = require('../debounce')

local jestGlobals = require('@pkg/@jsdotlua/jest-globals')

local expect = jestGlobals.expect
local jest = jestGlobals.jest
local it = jestGlobals.it
local beforeEach = jestGlobals.beforeEach

local fn
local fnMock

beforeEach(function()
    fnMock, fn = jest.fn()
end)

it('calls the function once within a frame', function()
    local debounced = debounce(1, fn)
    debounced()
    debounced()
    expect(fnMock).toHaveBeenCalledTimes(1)
end)

it('calls the function again after the duration has passed', function()
    local debounced = debounce(0, fn)
    debounced()
    task.wait()
    debounced()
    expect(fnMock).toHaveBeenCalledTimes(2)
end)
