local X=script.Parent.Parent.Parent.Parent.Parent local k=require(X.Dev.JestGlobals)local p=k.describe local H=k.expect local A=k.it local F=k.jest local x=require(script.Parent.Parent.reactiveVars)local R=x.makeVar p("\114\101\097\099\116\105\118\101\086\097\114\115",function()A("\115\104\111\117\108\100 \101\120\112\111\115\101 \102\117\110\099\116\105\111\110\115",function()(H(typeof(x.cacheSlot))).toBe("\116\097\098\108\101");(H(typeof(x.forgetCache))).toBe("\102\117\110\099\116\105\111\110");(H(typeof(x.makeVar))).toBe("\102\117\110\099\116\105\111\110");(H(typeof(x.recallCache))).toBe("\102\117\110\099\116\105\111\110")end)A("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \114\101\097\099\116\105\118\101 \118\097\114 \102\114\111\109 \109\097\107\101\086\097\114",function()local X=R("\105\110\105\116\105\097\108 \118\097\108\117\101");(H(typeof((getmetatable(X)).__call))).toBe("\102\117\110\099\116\105\111\110");(H(typeof(X.onNextChange))).toBe("\102\117\110\099\116\105\111\110");(H(typeof(X.attachCache))).toBe("\102\117\110\099\116\105\111\110");(H(typeof(X.forgetCache))).toBe("\102\117\110\099\116\105\111\110")end)A("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \114\101\097\099\116\105\118\101 \118\097\114 \119\105\116\104 \105\110\105\116\105\097\108 \118\097\108\117\101",function()local X=R("\105\110\105\116\105\097\108 \118\097\108\117\101");(H(X())).toBe("\105\110\105\116\105\097\108 \118\097\108\117\101")end)A("\115\104\111\117\108\100 \099\097\108\108 \097 \108\105\115\116\101\110\101\114 \119\104\101\110 \118\097\108\117\101 \099\104\097\110\103\101\115",function()local X=R("\105\110\105\116\105\097\108 \118\097\108\117\101")local k=F.fn()X:onNextChange(k);(H(X("\097\110\111\116\104\101\114 \118\097\108\117\101"))).toBe("\097\110\111\116\104\101\114 \118\097\108\117\101");(H(k)).toHaveBeenCalledTimes(1);(H(k)).toHaveBeenCalledWith("\097\110\111\116\104\101\114 \118\097\108\117\101")k.mockClear()X:onNextChange(k);(H(X("\121\101\116 \097\110\111\116\104\101\114 \118\097\108\117\101"))).toBe("\121\101\116 \097\110\111\116\104\101\114 \118\097\108\117\101");(H(k)).toHaveBeenCalledTimes(1);(H(k)).toHaveBeenCalledWith("\121\101\116 \097\110\111\116\104\101\114 \118\097\108\117\101")k.mockClear()X:onNextChange(k);(H(X("\121\101\116 \097\110\111\116\104\101\114 \118\097\108\117\101"))).toBe("\121\101\116 \097\110\111\116\104\101\114 \118\097\108\117\101");(H(k)).toHaveBeenCalledTimes(0)end)end)return{}
--[[
 * Copyright (c) Roblox Corporation
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
]]
-- ROBLOX no upstream
local rootWorkspace = script.Parent.Parent.Parent.Parent.Parent

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

local reactiveVarsModule = require(script.Parent.Parent.reactiveVars)
local makeVar = reactiveVarsModule.makeVar

describe("reactiveVars", function()
	it("should expose functions", function()
		expect(typeof(reactiveVarsModule.cacheSlot)).toBe("table")
		expect(typeof(reactiveVarsModule.forgetCache)).toBe("function")
		expect(typeof(reactiveVarsModule.makeVar)).toBe("function")
		expect(typeof(reactiveVarsModule.recallCache)).toBe("function")
	end)

	it("should return a reactive var from makeVar", function()
		local rv = makeVar("initial value")

		expect(typeof(getmetatable(rv).__call)).toBe("function")
		expect(typeof(rv.onNextChange)).toBe("function")
		expect(typeof(rv.attachCache)).toBe("function")
		expect(typeof(rv.forgetCache)).toBe("function")
	end)

	it("should return a reactive var with initial value", function()
		local rv = makeVar("initial value")

		expect(rv()).toBe("initial value")
	end)

	it("should call a listener when value changes", function()
		local rv = makeVar("initial value")
		local listener = jest.fn()

		rv:onNextChange(listener)
		expect(rv("another value")).toBe("another value")
		expect(listener).toHaveBeenCalledTimes(1)
		expect(listener).toHaveBeenCalledWith("another value")

		listener.mockClear()
		rv:onNextChange(listener)
		expect(rv("yet another value")).toBe("yet another value")
		expect(listener).toHaveBeenCalledTimes(1)
		expect(listener).toHaveBeenCalledWith("yet another value")

		listener.mockClear()
		rv:onNextChange(listener)
		expect(rv("yet another value")).toBe("yet another value")
		expect(listener).toHaveBeenCalledTimes(0)
	end)
end)

return {}
