local M=script.Parent.Parent local P=require(M.Dev.JestGlobals)local V=P.expect return function()local M beforeEach(function()M=_G.Observable end)describe("\099\111\110\115\116\114\117\099\116\111\114",function()it("\116\104\114\111\119\115 \105\102 \099\097\108\108\101\100 \097\115 \097 \102\117\110\099\116\105\111\110",function()(V(function()M(function() end)M.__call(function() end)end)).toThrow()end)it("\116\104\114\111\119\115 \105\102 \116\104\101 \097\114\103\117\109\101\110\116 \105\115 \110\111\116 \099\097\108\108\097\098\108\101\044 \097\114\103\117\109\101\110\116\058 \116\097\098\108\101",function()(V(function()M.new({})end)).toThrow("\079\098\115\101\114\118\097\098\108\101 \105\110\105\116\105\097\108\105\122\101\114 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end)it("\116\104\114\111\119\115 \105\102 \116\104\101 \097\114\103\117\109\101\110\116 \105\115 \110\111\116 \099\097\108\108\097\098\108\101\044 \097\114\103\117\109\101\110\116\058 \110\111\110\101",function()(V(function()M.new()end)).toThrow("\079\098\115\101\114\118\097\098\108\101 \105\110\105\116\105\097\108\105\122\101\114 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end)it("\116\104\114\111\119\115 \105\102 \116\104\101 \097\114\103\117\109\101\110\116 \105\115 \110\111\116 \099\097\108\108\097\098\108\101\044 \097\114\103\117\109\101\110\116\058 \049",function()(V(function()M.new(1)end)).toThrow("\079\098\115\101\114\118\097\098\108\101 \105\110\105\116\105\097\108\105\122\101\114 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end)it("\116\104\114\111\119\115 \105\102 \116\104\101 \097\114\103\117\109\101\110\116 \105\115 \110\111\116 \099\097\108\108\097\098\108\101\044 \097\114\103\117\109\101\110\116\058 \'\115\116\114\105\110\103\'",function()(V(function()M.new("\115\116\114\105\110\103")end)).toThrow("\079\098\115\101\114\118\097\098\108\101 \105\110\105\116\105\097\108\105\122\101\114 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end)it("\097\099\099\101\112\116\115 \097 \102\117\110\099\116\105\111\110 \097\114\103\117\109\101\110\116",function()(V(function()M.new(function() end)end)).never.toThrow("\079\098\115\101\114\118\097\098\108\101 \105\110\105\116\105\097\108\105\122\101\114 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")end)it("\105\115 \116\104\101 \118\097\108\117\101 \111\102 \079\098\115\101\114\118\097\098\108\101\046\095\095\105\110\100\101\120",function()(V(M)).toBe(M.__index)end)it("\100\111\101\115 \110\111\116 \099\097\108\108 \116\104\101 \115\117\098\115\099\114\105\098\101\114 \102\117\110\099\116\105\111\110",function()local P=0 M.new(function()P=P+1 end);(V(P)).toBe(0)end)end)end
-- ROBLOX upstream https://github.com/zenparsing/zen-observable/blob/v0.8.15/test/constructor.js

local rootWorkspace = script.Parent.Parent

local JestGlobals = require(rootWorkspace.Dev.JestGlobals)
local jestExpect = JestGlobals.expect

return function()
	-- ROBLOX deviation: upstream a global variable is created in the test setup.
	-- A local variable is created to avoid using _G.Observable in every test
	local Observable
	beforeEach(function()
		Observable = _G.Observable
	end)
	describe("constructor", function()
		it("throws if called as a function", function()
			jestExpect(function()
				Observable(function() end)
				Observable.__call(function() end)
			end).toThrow()
		end)

		it("throws if the argument is not callable, argument: table", function()
			jestExpect(function()
				Observable.new({})
			end).toThrow("Observable initializer must be a function")
		end)

		it("throws if the argument is not callable, argument: none", function()
			jestExpect(function()
				Observable.new()
			end).toThrow("Observable initializer must be a function")
		end)

		it("throws if the argument is not callable, argument: 1", function()
			jestExpect(function()
				Observable.new(1)
			end).toThrow("Observable initializer must be a function")
		end)

		it("throws if the argument is not callable, argument: 'string'", function()
			jestExpect(function()
				Observable.new("string")
			end).toThrow("Observable initializer must be a function")
		end)

		it("accepts a function argument", function()
			jestExpect(function()
				Observable.new(function() end)
			end).never.toThrow("Observable initializer must be a function")
		end)

		it("is the value of Observable.__index", function()
			jestExpect(Observable).toBe(Observable.__index)
		end)

		it("does not call the subscriber function", function()
			local called = 0
			Observable.new(function()
				called = called + 1
			end)
			jestExpect(called).toBe(0)
		end)
	end)
end
