-- ROBLOX deviation: wrap in function to pass jests methods (it, describe, etc)

local each = function(jestMethods_: Object?)
	local jestMethods = (if jestMethods_ ~= nil then jestMethods_ else {}) :: Object
	--[[
		ROBLOX deviation START: TestEZ it/test/describe are functions, make them callable objects
		to handle them the same way as jest's API and support both.
	]]
	Array.forEach(Object.keys(jestMethods), function(key)
		local maybeMethod = jestMethods[key]
		jestMethods[key] = if typeof(maybeMethod) == "function"
			then setmetatable({}, {
				__call = function(_self, ...)
					return maybeMethod(...)
				end,
			})
			else maybeMethod
	end)
	-- ROBLOX deviation END
	return setmetatable({
		withGlobal = function(g: Global)
			return function(table_: Global_EachTable, ...)
				return install(g, maybeHandleTemplateString(table_), ...)
			end
		end,
	}, {
		__call = function(_self, table_: Global_EachTable, ...): ReturnType<typeof(install)>
			-- ROBLOX deviation: jestMethods, are passed as parameters, not taken from global
			return install(jestMethods :: Global, maybeHandleTemplateString(table_), ...)
		end,
	})
end

exports.bind = bind

exports.default = each

exports.NIL = NIL

return exports
