mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 03:36:11 +00:00
test: simplify gc testing
This commit is contained in:
parent
8ca299f671
commit
0c68ff760f
6 changed files with 111 additions and 49 deletions
|
|
@ -1,4 +1,5 @@
|
|||
local atom = require(script.Parent.Parent.atom)
|
||||
local derive = require(script.Parent.Parent.derive)
|
||||
local effect = require(script.Parent.Parent.effect)
|
||||
local store = require(script.Parent.Parent.store)
|
||||
local subscribe = require(script.Parent.Parent.subscribe)
|
||||
|
|
@ -35,4 +36,26 @@ return function()
|
|||
end)
|
||||
expect(value).to.equal(1)
|
||||
end)
|
||||
|
||||
it("batches derived atoms", function()
|
||||
local source = atom(1)
|
||||
local updates = 0
|
||||
local computed = 0
|
||||
local double = derive(function()
|
||||
computed += 1
|
||||
return source() * 2
|
||||
end)
|
||||
computed = 0 -- derived atoms will run once initially
|
||||
subscribe(double, function()
|
||||
updates += 1
|
||||
end)
|
||||
store.batch(function()
|
||||
source(2)
|
||||
source(3)
|
||||
source(4)
|
||||
end)
|
||||
expect(updates).to.equal(1)
|
||||
expect(computed).to.equal(1)
|
||||
expect(double()).to.equal(8)
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue