Skip to content

Commit

Permalink
Improved state testing.
Browse files Browse the repository at this point in the history
Added additional tests for state disconnections.
  • Loading branch information
SirMallard committed Sep 3, 2024
1 parent b408e7a commit a09fd07
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/State.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit a09fd07

Please sign in to comment.