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