mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +00:00
refactor!: minimal react api
This commit is contained in:
parent
047be71eaa
commit
f2f7a16599
10 changed files with 59 additions and 144 deletions
42
src/__tests__/react/useAtom.spec.luau
Normal file
42
src/__tests__/react/useAtom.spec.luau
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
local atom = require(script.Parent.Parent.Parent.atom)
|
||||
local useAtom = require(script.Parent.Parent.Parent.react.useAtom)
|
||||
local renderHook = require(script.Parent.helpers.renderHook)
|
||||
|
||||
return function()
|
||||
it("tracks atom state", function()
|
||||
local source = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(source)
|
||||
end)
|
||||
expect(hook.result).to.equal(0)
|
||||
source(1)
|
||||
expect(hook.result).to.equal(1)
|
||||
end)
|
||||
|
||||
it("accepts a molecule", function()
|
||||
local source = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(function()
|
||||
return 2 * source()
|
||||
end)
|
||||
end)
|
||||
expect(hook.result).to.equal(0)
|
||||
source(1)
|
||||
expect(hook.result).to.equal(2)
|
||||
end)
|
||||
|
||||
it("tracks dependencies", function()
|
||||
local source = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(source, { source })
|
||||
end)
|
||||
expect(hook.result).to.equal(0)
|
||||
source(1)
|
||||
expect(hook.result).to.equal(1)
|
||||
source = atom(0)
|
||||
hook.rerender()
|
||||
expect(hook.result).to.equal(0)
|
||||
source(1)
|
||||
expect(hook.result).to.equal(1)
|
||||
end)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue