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("\102\105\108\116\101\114",function()it("\102\105\108\116\101\114\115 \116\104\101 \114\101\115\117\108\116\115 \117\115\105\110\103 \116\104\101 \115\117\112\112\108\105\101\100 \099\097\108\108\098\097\099\107",function()local P={};(((M.from({1;2;3,4})):filter(function(M)return M>2 end)):forEach(function(M)table.insert(P,M)return#P end)):expect();(V(P)).toEqual({3;4})end)it("\101\114\114\111\114\115 \119\104\101\110 \103\105\118\101\110 \110\111\110-\102\117\110\099\116\105\111\110",function()(V(function()local P=31337;((M.from({1;2;3;4})):filter(P)):expect()end)).toThrow("\051\049\051\051\055 \105\115 \110\111\116 \097 \102\117\110\099\116\105\111\110")end)end)end
-- ROBLOX upstream https://github.com/zenparsing/zen-observable/blob/v0.8.15/test/filter.js
--!strict
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("filter", function()
		it("filters the results using the supplied callback", function()
			local list = {}
			Observable.from({ 1, 2, 3, 4 })
				:filter(function(x)
					return x > 2
				end)
				:forEach(function(x)
					table.insert(list, x)
					return #list
				end)
				:expect()
			jestExpect(list).toEqual({ 3, 4 })
		end)
		-- ROBLOX TODO: submit this new test upstream
		it("errors when given non-function", function()
			jestExpect(function()
				local NOT_A_FUNCTION = 31337
				-- ROBLOX FIXME Luau: type checking should prevent this abuse, but we need recursive type workarounds removed first
				Observable.from({ 1, 2, 3, 4 }):filter(NOT_A_FUNCTION):expect()
			end).toThrow("31337 is not a function")
		end)
	end)
end
