local d=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local i=d.expect local F=d.jest local k=d.beforeEach local b=d.describe local a=d.it local M local B local z local H k(function()F.resetModules()M=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\067\111\110\116\101\120\116\046\110\101\119\046\108\117\097\117")B=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\046\110\101\119\046\108\117\097\117")z=require("\046\046\047\082\101\097\099\116\082\111\111\116\084\097\103\115")H=(require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\104\097\114\101\100")).ReactFeatureFlags H.disableLegacyContext=false end)b("\067\111\110\116\101\120\116 \115\116\097\099\107",function()a("\115\104\111\117\108\100 \116\104\114\111\119 \119\104\101\110 \112\117\115\104\105\110\103 \116\111 \116\111\112 \108\101\118\101\108 \111\102 \110\111\110-\101\109\112\116\121 \115\116\097\099\107",function()local d=B.createHostRootFiber(z.BlockingRoot)local F={foo=1}M.pushTopLevelContextObject(d,F,true);(i(function()local i={bar=2}M.pushTopLevelContextObject(d,i,true)end)).toThrow("\085\110\101\120\112\101\099\116\101\100 \099\111\110\116\101\120\116 \102\111\117\110\100 \111\110 \115\116\097\099\107\046")end)a("\115\104\111\117\108\100 \116\104\114\111\119 \105\102 \119\104\101\110 \105\110\118\097\108\105\100\097\116\105\110\103 \097 \112\114\111\118\105\100\101\114 \116\104\097\116 \105\115\110\'\116 \105\110\105\116\105\097\108\105\122\101\100",function()local d=B.createHostRootFiber(z.BlockingRoot);(i(function()M.invalidateContextProvider(d,nil,true)end)).toThrow("\069\120\112\101\099\116\101\100 \116\111 \104\097\118\101 \097\110 \105\110\115\116\097\110\099\101 \098\121 \116\104\105\115 \112\111\105\110\116\046")end)end)
-- awaiting pull request: https://github.com/facebook/react/pull/20155
--[[*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @emails react-core
 * @jest-environment node
]]

local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local jest = JestGlobals.jest
local beforeEach = JestGlobals.beforeEach
local describe = JestGlobals.describe
local it = JestGlobals.it

local ReactFiberContext
local ReactFiber
local ReactRootTags
local ReactFeatureFlags

beforeEach(function()
	jest.resetModules()

	ReactFiberContext = require("../ReactFiberContext.new.luau")
	ReactFiber = require("../ReactFiber.new.luau")
	ReactRootTags = require("../ReactRootTags")
	ReactFeatureFlags = require("@pkg/@jsdotlua/shared").ReactFeatureFlags
	ReactFeatureFlags.disableLegacyContext = false
end)

describe("Context stack", function()
	it("should throw when pushing to top level of non-empty stack", function()
		local fiber = ReactFiber.createHostRootFiber(ReactRootTags.BlockingRoot)
		local context = {
			foo = 1,
		}
		-- The first call here is a valid use of pushTopLevelContextObject
		ReactFiberContext.pushTopLevelContextObject(fiber, context, true)
		jestExpect(function()
			local moreContext = {
				bar = 2,
			}
			ReactFiberContext.pushTopLevelContextObject(fiber, moreContext, true)
		end).toThrow("Unexpected context found on stack.")
	end)

	it("should throw if when invalidating a provider that isn't initialized", function()
		local fiber = ReactFiber.createHostRootFiber(ReactRootTags.BlockingRoot)
		jestExpect(function()
			ReactFiberContext.invalidateContextProvider(fiber, nil, true)
		end).toThrow("Expected to have an instance by this point.")
	end)
end)
