local e=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 k=e.expect local p=e.beforeEach local f=e.it local S=e.jest local A local M local O local X local o p(function()S.resetModules()S.useFakeTimers()local e=(require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\104\097\114\101\100")).ReactFeatureFlags e.debugRenderPhaseSideEffectsForStrictMode=false A=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116")M=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116-\114\111\098\108\111\120")o=Instance.new("\070\111\108\100\101\114")O=M.createRoot(o)X=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\099\104\101\100\117\108\101\114")end)f("\115\104\111\117\108\100 \112\114\111\118\105\100\101 \097 \117\115\101\102\117\108 \101\114\114\111\114 \119\104\101\110 \105\110\105\116\105\097\108 \112\114\111\112 \097\115\115\105\103\110\109\101\110\116 \102\097\105\108\115",function()O:render(A.createElement("\070\114\097\109\101",{},{Root=A.createElement("\084\101\120\116\076\097\098\101\108",{AbsentProp=1})}));(k(function()(k(X.unstable_flushAllWithoutAsserting)).toErrorDev("\069\114\114\111\114 \097\112\112\108\121\105\110\103 \105\110\105\116\105\097\108 \112\114\111\112\115 \116\111 \082\111\098\108\111\120 \073\110\115\116\097\110\099\101 \'\082\111\111\116\' \040\084\101\120\116\076\097\098\101\108\041")end)).toThrow()end)f("\115\104\111\117\108\100 \112\114\111\118\105\100\101 \097 \117\115\101\102\117\108 \101\114\114\111\114 \119\104\101\110 \097 \112\114\111\112\115 \117\112\100\097\116\101 \102\097\105\108\115",function()O:render(A.createElement("\070\114\097\109\101",{},{Root=A.createElement("\084\101\120\116\076\097\098\101\108",{Text="\079\107\097\121\033"})}))X.unstable_flushAllWithoutAsserting()O:render(A.createElement("\070\114\097\109\101",{},{Root=A.createElement("\084\101\120\116\076\097\098\101\108",{Text="\078\111\116 \103\111\111\100";AbsentProp=1})}));(k(function()(k(X.unstable_flushAllWithoutAsserting)).toErrorDev("\069\114\114\111\114 \117\112\100\097\116\105\110\103 \112\114\111\112\115 \111\110 \082\111\098\108\111\120 \073\110\115\116\097\110\099\101 \'\082\111\111\116\' \040\084\101\120\116\076\097\098\101\108\041\058")end)).toThrow()end)f("\115\104\111\117\108\100 \112\114\111\118\105\100\101 \097 \117\115\101\102\117\108 \101\114\114\111\114 \119\104\101\110 \097 \098\105\110\100\105\110\103 \117\112\100\097\116\101 \102\097\105\108\115",function()local e,p=A.createBinding(nil)O:render(A.createElement("\070\114\097\109\101",{},{Root=A.createElement("\084\101\120\116\076\097\098\101\108",{NextSelectionLeft=e})}))X.unstable_flushAllWithoutAsserting();(k(function()(k(function()p("\110\111\116 \097\110 \073\110\115\116\097\110\099\101")end)).toErrorDev("\069\114\114\111\114 \117\112\100\097\116\105\110\103 \098\105\110\100\105\110\103 \111\114 \114\101\102 \097\115\115\105\103\110\101\100 \116\111 \107\101\121 \078\101\120\116\083\101\108\101\099\116\105\111\110\076\101\102\116 \111\102 \'\082\111\111\116\' \040\084\101\120\116\076\097\098\101\108\041\046",{withoutStack=true})end)).toThrow()end)
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local beforeEach = JestGlobals.beforeEach
local it = JestGlobals.it
local jest = JestGlobals.jest

local React
local ReactRoblox
local reactRobloxRoot
local Scheduler
local parent

beforeEach(function()
	jest.resetModules()
	jest.useFakeTimers()
	local ReactFeatureFlags = require("@pkg/@jsdotlua/shared").ReactFeatureFlags
	ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false

	React = require("@pkg/@jsdotlua/react")
	ReactRoblox = require("@pkg/@jsdotlua/react-roblox")
	parent = Instance.new("Folder")
	reactRobloxRoot = ReactRoblox.createRoot(parent)
	Scheduler = require("@pkg/@jsdotlua/scheduler")
end)

it("should provide a useful error when initial prop assignment fails", function()
	reactRobloxRoot:render(
		React.createElement(
			"Frame",
			{},
			{ Root = React.createElement("TextLabel", { AbsentProp = 1 }) }
		)
	)

	jestExpect(function()
		jestExpect(Scheduler.unstable_flushAllWithoutAsserting).toErrorDev(
			"Error applying initial props to Roblox Instance 'Root' (TextLabel)"
		)
	end).toThrow()
end)

it("should provide a useful error when a props update fails", function()
	reactRobloxRoot:render(
		React.createElement(
			"Frame",
			{},
			{ Root = React.createElement("TextLabel", { Text = "Okay!" }) }
		)
	)

	Scheduler.unstable_flushAllWithoutAsserting()

	reactRobloxRoot:render(React.createElement("Frame", {}, {
		Root = React.createElement("TextLabel", { Text = "Not good", AbsentProp = 1 }),
	}))

	jestExpect(function()
		jestExpect(Scheduler.unstable_flushAllWithoutAsserting).toErrorDev(
			"Error updating props on Roblox Instance 'Root' (TextLabel):"
		)
	end).toThrow()
end)

it("should provide a useful error when a binding update fails", function()
	local neighbor, setNeighbor = React.createBinding(nil)
	reactRobloxRoot:render(React.createElement("Frame", {}, {
		Root = React.createElement("TextLabel", { NextSelectionLeft = neighbor }),
	}))

	Scheduler.unstable_flushAllWithoutAsserting()

	jestExpect(function()
		jestExpect(function()
			setNeighbor("not an Instance")
		end).toErrorDev(
			"Error updating binding or ref assigned to key NextSelectionLeft of 'Root' (TextLabel).",
			{ withoutStack = true }
		)
	end).toThrow()
end)
