diff --git a/src/binder/src/Shared/Binder.Loading.spec.lua b/src/binder/src/Shared/Binder.Loading.spec.lua index 3e826a67e6b..933cb166252 100644 --- a/src/binder/src/Shared/Binder.Loading.spec.lua +++ b/src/binder/src/Shared/Binder.Loading.spec.lua @@ -5,13 +5,18 @@ local require = require(script.Parent.loader).load(script) +local Binder = require("Binder") local BinderTestUtils = require("BinderTestUtils") local Jest = require("Jest") +local JestUtils = require("JestUtils") local Signal = require("Signal") local describe = Jest.Globals.describe local expect = Jest.Globals.expect local it = Jest.Globals.it +local jest = Jest.Globals.jest + +local NOT_STARTED_WARNING_DELAY_SECONDS = 30 describe("Binder load abandonment", function() it("does not bind a class when the instance is removed while the constructor yields", function() @@ -49,3 +54,27 @@ describe("Binder load abandonment", function() controller:Destroy() end) end) + +describe("Binder not started warning", function() + it("warns only once the binder has gone unstarted for the full delay", function() + local controller = BinderTestUtils.setup() + JestUtils.useFakeTimers() + + local warnSpy = jest.spyOn(jest.globalEnv, "warn").mockImplementation(function() end) + controller.maid:GiveTask(function() + warnSpy.mockRestore() + end) + + local binder = controller.maid:Add(Binder.new(controller.uniqueTag(), BinderTestUtils.noopConstructor)) + binder:Init() + local warning = string.format("Binder %q is not loaded. Call :Start() on it!", binder:GetTag()) + + jest.advanceTimersByTime(5 * 1000) + expect(warnSpy).never.toHaveBeenCalledWith(warning) + + jest.advanceTimersByTime((NOT_STARTED_WARNING_DELAY_SECONDS - 5) * 1000) + expect(warnSpy).toHaveBeenCalledWith(warning) + + controller:Destroy() + end) +end) diff --git a/src/binder/src/Shared/Binder.lua b/src/binder/src/Shared/Binder.lua index 3c42887cd41..6304d1e289b 100644 --- a/src/binder/src/Shared/Binder.lua +++ b/src/binder/src/Shared/Binder.lua @@ -38,6 +38,8 @@ local Observable = require("Observable") local Promise = require("Promise") local Signal = require("Signal") +local NOT_STARTED_WARNING_DELAY_SECONDS = 30 + local Binder = {} Binder.__index = Binder Binder.ClassName = "Binder" @@ -180,7 +182,7 @@ function Binder:Init(...) self._args = {} end - self._maid._warning = task.delay(5, function() + self._maid._warning = task.delay(NOT_STARTED_WARNING_DELAY_SECONDS, function() warn(string.format("Binder %q is not loaded. Call :Start() on it!", self._tagName)) end) end