From a09fd076ee32b0370f16ce09ff3d15bc19b2bc6c Mon Sep 17 00:00:00 2001 From: Sir Mallard <73789875+SirMallard@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:54:18 +0100 Subject: [PATCH] Improved state testing. Added additional tests for state disconnections. --- tests/State.spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/State.spec.lua b/tests/State.spec.lua index 53c7065..5593b5a 100644 --- a/tests/State.spec.lua +++ b/tests/State.spec.lua @@ -10,6 +10,10 @@ return function() end) describe("State", function() + it("Should be a state", function() + expect(state).to.be.a("table") + expect(state.ID).to.be.a("string") + end) it("SHOULD contain nil", function() expect(state:get()).to.equal(nil) expect(state.value).to.equal(nil) @@ -44,5 +48,20 @@ return function() state:set(10) expect(otherState:get()).to.equal(20) end) + it("SHOULD disconnect a function", function() + local number: number = 0 + local disconnect: () -> () = state:onChange(function(value: number) + number = value + end) + expect(disconnect).to.be.a("function") + expect(#state.ConnectedFunctions).to.equal(1) + expect(number).to.be.equal(0) + state:set(1) + expect(number).to.be.equal(1) + expect(disconnect()).to.equal(nil) + expect(#state.ConnectedFunctions).to.equal(0) + state:set(2) + expect(number).to.equal(1) + end) end) end