local I=script.Parent.Parent local p=I.Parent local l=p.Parent local t=require(l.Dev.JestGlobals)local o=t.expect local b=t.jest local q=t.describe local Y=t.it local S=t.beforeEach local X=t.afterEach q("\117\115\101\070\114\097\109\101",function()local t local q local W local v local w local P S(function()b.resetModules()P=b.fn()w=b.fn(function()return P end)b.mock(p.utils.RunService,function()return{RenderStepped={Connect=w}}end)t=require(l.Dev.Roact)q=require(l.Dev.ReactRoblox)W=(require(p.testUtils.bootstrapSync))(t,q)v=(require(I.useFrame))(t)end)X(function()b.unmock(p.utils.RunService)end)Y("\115\104\111\117\108\100 \099\097\108\108 \066\105\110\100\084\111\082\101\110\100\101\114\083\116\101\112",function()local I=Instance.new("\070\111\108\100\101\114")I.Name="\071\117\105\082\111\111\116"local p=W(I,function()v(function() end)return t.createElement("\070\111\108\100\101\114")end)wait();(o(w)).toHaveBeenCalledTimes(1)end)end)
local hooksWorkspace = script.Parent.Parent
local srcWorkspace = hooksWorkspace.Parent
local rootWorkspace = srcWorkspace.Parent

local JestGlobals = require(rootWorkspace.Dev.JestGlobals)
local jestExpect = JestGlobals.expect
local jest = JestGlobals.jest
local describe = JestGlobals.describe
local it = JestGlobals.it
local beforeEach = JestGlobals.beforeEach
local afterEach = JestGlobals.afterEach

describe("useFrame", function()
	local Roact
	local ReactRoblox
	local bootstrapSync
	local useFrame
	local Connect
	local Disconnect

	beforeEach(function()
		jest.resetModules()

		Disconnect = jest.fn()
		Connect = jest.fn(function()
			return Disconnect
		end)

		jest.mock(srcWorkspace.utils.RunService, function()
			return {
				RenderStepped = {
					Connect = Connect,
				},
			}
		end)

		--[[
			because we reset modules for each test we need to reimport
			- Roact
			- bootstrapSync
			so that they use the same Roact instance as `useFrame`
		]]
		Roact = require(rootWorkspace.Dev.Roact)
		ReactRoblox = require(rootWorkspace.Dev.ReactRoblox)
		bootstrapSync = require(srcWorkspace.testUtils.bootstrapSync)(Roact, ReactRoblox)
		useFrame = require(hooksWorkspace.useFrame)(Roact)
	end)

	afterEach(function()
		jest.unmock(srcWorkspace.utils.RunService)
	end)

	it("should call BindToRenderStep", function()
		local rootInstance = Instance.new("Folder")
		rootInstance.Name = "GuiRoot"

		local _stop = bootstrapSync(rootInstance, function()
			useFrame(function() end)
			return Roact.createElement("Folder")
		end)

		wait()
		jestExpect(Connect).toHaveBeenCalledTimes(1)
	end)
end)
