local V=require("\046\046\047\121\105\101\108\100\087\104\105\108\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()k.mockReturnValue(false)end)R("\114\117\110\115 \116\104\101 \102\117\110\099\116\105\111\110 \111\110\099\101",function()V(.016666666666667,i);(G(k)).toHaveBeenCalledTimes(1)end)R("\114\117\110\115 \116\104\101 \102\117\110\099\116\105\111\110 \116\119\105\099\101",function()k.mockReturnValueOnce(true)V(.016666666666667,i);(G(k)).toHaveBeenCalledTimes(2)end)R("\114\117\110\115 \116\104\101 \102\117\110\099\116\105\111\110 \117\110\116\105\108 \116\104\101 \100\117\114\097\116\105\111\110 \104\097\115 \112\097\115\115\101\100",function()k.mockReturnValue(true)V({interval=.016666666666667;duration=.5},i);(G(k)).toHaveBeenCalled()end)
local yieldWhile = require('../yieldWhile')

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()
    fnMock.mockReturnValue(false)
end)

it('runs the function once', function()
    yieldWhile(1 / 60, fn)
    expect(fnMock).toHaveBeenCalledTimes(1)
end)

it('runs the function twice', function()
    fnMock.mockReturnValueOnce(true)
    yieldWhile(1 / 60, fn)
    expect(fnMock).toHaveBeenCalledTimes(2)
end)

it('runs the function until the duration has passed', function()
    fnMock.mockReturnValue(true)
    yieldWhile({ interval = 1 / 60, duration = 0.5 }, fn)
    expect(fnMock).toHaveBeenCalled()
end)
