mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 04:14:08 +00:00
refactor: remove pnpm, fix tests
This commit is contained in:
parent
861ee5acd7
commit
e34b0c9aca
65 changed files with 353 additions and 2458 deletions
13
tests/react-charm/spec.luau
Normal file
13
tests/react-charm/spec.luau
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local suite = require("../suite")
|
||||
|
||||
local describe = suite.describe
|
||||
|
||||
local function test(name: string)
|
||||
describe(name, function()
|
||||
return require(`./{name}.spec`) :: any
|
||||
end)
|
||||
end
|
||||
|
||||
test("useAtom")
|
||||
|
||||
return {}
|
||||
50
tests/react-charm/useAtom.spec.luau
Normal file
50
tests/react-charm/useAtom.spec.luau
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local ServerScriptService = game:GetService("ServerScriptService")
|
||||
|
||||
local Charm = require(ReplicatedStorage.Packages.Charm)
|
||||
local ReactCharm = require(ReplicatedStorage.Packages.ReactCharm)
|
||||
local renderHook = require(ServerScriptService.Tests.utils.renderHook)
|
||||
local suite = require(ServerScriptService.Tests.suite)
|
||||
|
||||
local atom = Charm.atom
|
||||
local useAtom = ReactCharm.useAtom
|
||||
local test = suite.test
|
||||
|
||||
test("tracks atom state", function()
|
||||
local state = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(state)
|
||||
end)
|
||||
assert(hook.result == 0)
|
||||
state(1)
|
||||
assert(hook.result == 1)
|
||||
end)
|
||||
|
||||
test("accepts a selector", function()
|
||||
local state = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(function()
|
||||
return 2 * state()
|
||||
end)
|
||||
end)
|
||||
assert(hook.result == 0)
|
||||
state(1)
|
||||
assert(hook.result == 2)
|
||||
end)
|
||||
|
||||
test("tracks dependencies", function()
|
||||
local state = atom(0)
|
||||
local hook = renderHook(function()
|
||||
return useAtom(state, { state })
|
||||
end)
|
||||
assert(hook.result == 0)
|
||||
state(1)
|
||||
assert(hook.result == 1)
|
||||
state = atom(0)
|
||||
hook.rerender()
|
||||
assert(hook.result == 0)
|
||||
state(1)
|
||||
assert(hook.result == 1)
|
||||
end)
|
||||
|
||||
return {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue