SolidJSS
SolidJS3y ago
13 replies
Song

TypeError when using `createResource` in vitest

I'm new to Solidjs, and I'm learing how to test functions in vitest, it cause the error TypeError: Cannot read properties of undefined (reading 'id'), does anyone know how to solve it? there is no solution when asking ChatGPT🥲
describe('test createResource', () => {
  test('res', async () => {
    const [num, setNum] = createSignal(1)
    const fetchUser = async (id: number) => id + 1
    const [foo, { mutate, refetch }] = createResource(num, fetchUser)
    console.log(foo.loading)
  })
})

my packages
"devDependencies": {
    "@solidjs/testing-library": "^0.7.0",
    "happy-dom": "^9.9.2",
    "solid-js": "^1.7.3",
    "typescript": "5.0.4",
    "vite": "^4.3.1",
    "vitest": "^0.30.1"
  },
Was this page helpful?