S
SolidJS3mo ago
gdt

How to get simple reactivity to work within unit tests?

Hi, I'm probably missing something very obvious here, but I can't get this simple unit test to pass. I've been using solid for years but this is the first time I've actually tried to do this:
test('reactivity', () => {
// createRoot(() => {
const [get, set] = createSignal(0)
const m = createMemo(() => get())
set(5)
expect(m()).toBe(5)
// })
})
test('reactivity', () => {
// createRoot(() => {
const [get, set] = createSignal(0)
const m = createMemo(() => get())
set(5)
expect(m()).toBe(5)
// })
})
1 Reply
zulu
zulu3mo ago
you need to test with browser build node build does not have reactivity this is what https://github.com/solidjs-community/solid-primitives is doing using vitest https://github.com/solidjs-community/solid-primitives/blob/main/configs/vitest.config.ts or for simpler setup, you can try to run with "browser" condition
node --conditions=browser testfile.js
node --conditions=browser testfile.js

Did you find this page helpful?