Replies: 3 comments 8 replies
-
Really the only testing examples we have published are the ones in this repo. For example, see the ecosystem testing utils in the React package's tests. We use React Testing Library to test Zedux and it works out of the box as far as I've known. I've never seen this error, but it looks like it's only possible if you're extending the core package's I just set up a new test project with the latest versions of Simple import { atom, injectEffect, injectStore, useAtomValue } from '@zedux/react'
import axios from 'axios'
import { FC } from 'react'
interface Post {
body: string
id: number
title: string
}
const postAtom = atom('post', (id: number) => {
const store = injectStore<null | Post>(null)
injectEffect(() => {
const run = async () => {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`)
store.setState(data)
}
run()
}, [id])
return store
})
export const Post: FC<{ postId: number; setPostId: (id: number) => void }> = ({
postId,
setPostId,
}) => {
const data = useAtomValue(postAtom, [postId])
const status = data ? 'success' : 'loading'
return (
<div>
<div>
<a onClick={() => setPostId(-1)} href="#">
Back
</a>
</div>
{!postId || status === 'loading' ? (
'Loading...'
) : (
<>
<h1>{data?.title}</h1>
<div>
<p>{data?.body}</p>
</div>
</>
)}
</div>
)
} Simple test: import { render, screen } from '@testing-library/react'
import { Post } from './Post'
test('shows post', async () => {
const result = render(<Post postId={1} setPostId={() => {}} />)
await new Promise(resolve => setTimeout(resolve, 1000))
expect(screen.getByRole('heading').innerHTML).toBe(
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
)
}) @zdubin are you able to set up a reproduction in codesandbox/similar? Or do you know of anything out of the ordinary you might be doing with the |
Beta Was this translation helpful? Give feedback.
-
Let me give you some more context. I'm writing a parcel using Single SPA: https://single-spa.js.org/docs/parcels-overview/. Zedux atoms work perfectly in the parcel, but when I run the test of a component using the atoms, I get the following stack trace. Do I need to do any special setup? I tried with and without EcosystemProvider, but I got the same error. My company doesn't allow my to share any code, but if I need to I can set up an external Single SPA parcel, add Zedux Atoms and run it in standalone mode with React Testing Library and see if I see the same errors.
) |
Beta Was this translation helpful? Give feedback.
-
Thank you for your quick work. I'm trying it on my home desktop before I do the same at work. Do I have to upgrade to React 19? I'm getting errors that indicate I do?
|
Beta Was this translation helpful? Give feedback.
-
Hello,
What's the best way to go about testing Zedux with React Testing Library? Do you have some examples that I can start with?
This is the initial error "Error: Uncaught [TypeError: hierarchyConfig.isNode is not a function]"
Thanks
Beta Was this translation helpful? Give feedback.
All reactions