Unexpected token in testing render method
Hello, I'm just trying to test something and experienced with this problem. I follow the guide from https://docs.solidjs.com/guides/how-to-guides/testing-in-solid/vitest#creating-tests
I can't get why that problem happens.
25 Replies
render expects a function as its first argument.
If you used typescript, you would have gotten a type warning.
So you need to use
render(() => <AdminUserChange />)
.It did't solve the problem. But what really hellps is the changing of the test file extension from .js to .jsx.
Have no idea why ...
By the way , I use js, not typescript
And now I have this
Using the function instead of the component should solve at least one part of the problem. I am the maintainer of our testing-library.
Maybe you need to
await screen.findByRole('button')
inside an async testing function instead.
But usually, rendering is pretty instant.
Unless you have a Suspense or Show in there somewhere.
Can you show me the AdminUserChange component?
Or wait, maybe it finds more than one button.Yep it has 2
In which case, you should probably use
const { getByRole } = render(...)
and use that instead of screen.
or if they have different text, use screen.getByRole('button', { name: 'Update' })
.
Exchange Update for whatever text you are expecting.
not working
Stilll throws
Then you are using node 20
Yep I have just updated because of another problem
There are three workarounds for a change in node's module resolution that breaks vitest.
1. Inline all /solid-js/ deps,
2. resolve.alias-es for all solid imports,
3. downgrade node to 18+.
#1 is recommended.
I have already informed the vitest team of the issue, a later version should fix it so that the workaround can be removed.
I got this nasty problem so I tried to solve it by upgrading node to 20.
In your vite(st) config, you need something like
test: { ..., deps: { inline: [/solid-js/] } },
.
IIRC, at least. I'm currently on my cellphone.It should be correct, though: https://github.com/solidjs/solid-testing-library/issues/38#issuecomment-1564593881
GitHub
[test:vitest-run] TypeError: unmount is not a function · Issue #38 ...
All of a sudden, I started to get for tests like
That's my config
Just add the deps part to test.
I worked out! But there is another problem:(
Why did it decided I have 2 instaces of solid and how to tell it that my App is actually wrapped by Router?
Ah, you probably need to include
/@solidjs/
to the inlined deps as well.
Like this? It's not working
Wait
It solved the problem with multiple instances of solid!
But there is still the problem with Wrapping up the App with Router
Thank you! It works!
Happy to help. I hope your experience testing solid code is now smoother.
I'm a beginer in frontend testing so smoother is still not my case 🙂 But I'm keen on TDD and love testing backend in Python. I hope I manage to include TDD approach to my Solid js projects/
Good luck, then! 🍀