local M=script.Parent.Parent local P=require(M.Dev.JestGlobals)local V=P.expect local b=(require(script.Parent.properties)).testMethodProperty return function()local M beforeEach(function()M=_G.Observable end)describe("\111\098\115\101\114\118\101\114\046\099\108\111\115\101\100",function()it("\105\115 \097 \103\101\116\116\101\114 \111\110 \083\117\098\115\099\114\105\112\116\105\111\110\079\098\115\101\114\118\101\114\046\112\114\111\116\111\116\121\112\101",function()local P;(M.new(function(M)P=M end)):subscribe()b(P,"\099\108\111\115\101\100",{get=true;configurable=true;writable=true,length=1})end)it("\114\101\116\117\114\110\115 \102\097\108\115\101 \119\104\101\110 \116\104\101 \115\117\098\115\099\114\105\112\116\105\111\110 \105\115 \111\112\101\110",function()(M.new(function(M)(V(M.closed)).toBe(false)end)):subscribe()end)it("\114\101\116\117\114\110\115 \116\114\117\101 \119\104\101\110 \116\104\101 \115\117\098\115\099\114\105\112\116\105\111\110 \105\115 \099\111\109\112\108\101\116\101\100",function()local P;(M.new(function(M)P=M end)):subscribe()P:complete();(V(P.closed)).toBe(true)end)it("\114\101\116\117\114\110\115 \116\114\117\101 \119\104\101\110 \116\104\101 \115\117\098\115\099\114\105\112\116\105\111\110 \105\115 \101\114\114\111\114\101\100",function()local P;(M.new(function(M)P=M end)):subscribe(nil,function() end)P:error(nil);(V(P.closed)).toBe(true)end)end)end
-- ROBLOX upstream https://github.com/zenparsing/zen-observable/blob/v0.8.15/test/observer-closed.js
local rootWorkspace = script.Parent.Parent

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

local testMethodProperty = require(script.Parent.properties).testMethodProperty

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("observer.closed", function()
		it("is a getter on SubscriptionObserver.prototype", function()
			local observer
			Observable.new(function(x)
				observer = x
			end):subscribe()
			testMethodProperty(
				--ROBLOX deviation, getPrototypeof called in function
				observer,
				"closed",
				{ get = true, configurable = true, writable = true, length = 1 }
			)
		end)

		it("returns false when the subscription is open", function()
			Observable.new(function(observer)
				jestExpect(observer.closed).toBe(false)
			end):subscribe()
		end)

		it("returns true when the subscription is completed", function()
			local observer
			Observable.new(function(x)
				observer = x
			end):subscribe()
			observer:complete()
			jestExpect(observer.closed).toBe(true)
		end)

		it("returns true when the subscription is errored", function()
			local observer
			Observable.new(function(x)
				observer = x
			end):subscribe(nil, function() end)
			-- ROBLOX TODO: upstream test should at least pass in null
			observer:error(nil)
			jestExpect(observer.closed).toBe(true)
		end)
	end)
end
