-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Svelte Jester i18n help #7
Comments
Hey @kaydwithers! I'm not sure what i18n and router you're referring to but ... if they are Svelte packages that contain a This package is most likely what you're looking for -> https://www.npmjs.com/package/jest-svelte-resolver |
Thanks Rahim, I updated my comment with the router error. I installed the resolver and my babel looks good. I added svelte-i18n to the ignore and that works now. But the router is still erroring.
|
What's the error? Is it the same |
That's weird. It seems like it's not transforming that file. Could you share your Jest configuration? |
This is jest.config.js
|
The current configuration is ignoring transformations on any paths matching module.exports = {
// ...
transformIgnorePatterns: ['node_modules/(?!(svelte-spa-router|svelte-i18n)/)']
} Basically it means don't bother transforming anything inside |
Thanks for your help Rahim, the above helped. I also ended up having to import i18n and the below works.
|
Sorry to bother you again @mihar-22 , I'm having a bit of trouble with some other Svelte packages.
Do you know what might be wrong? |
I'm not sure but it might be because Try this: module.exports = {
// ...
transformIgnorePatterns: ['node_modules/(?!(svelte-spa-router|svelte-i18n|regexparam)/)']
} |
Yeah I tried that but no luck. My jest config looks like this.
|
Unfortunately I have no clue @kaydwithers. Could it be related to how you've implemented |
I did find this issue which is exactly the same as mine. I don't know how to resolve it though. |
I ended up finding a solution with
|
That's awesome @kaydwithers . I still can't understand why it doesn't work without using |
Hey @mihar-22, so sorry to disturb you again. Do you know of any examples on how to test with a router push? I'm using
|
I don't have any examples to link you but I'd do it something like this: import { render, screen, fireEvent } from '@testing-library/svelte'
it('should navigate me to about page', async () => {
render(App);
const aboutUsLink = screen.getByText(/about/i);
await fireEvent.click(aboutUsLink);
// This will wait for the text to appear on the page. Check the docs for more info.
await screen.findByText('About Us Heading');
}); Try to stick to what the user would naturally see on the page, and the flow of events you'd expect going through the actual application. Don't unnaturally call functions or mock anything that doesn't need to be mocked. You'll get more effective + resilient tests in the end. |
Unfortunately we don't actually have buttons on the page. we have an app that progresses to other pages by scanning things i.e. a passport. So I need to mock a router push and test if the page has the text I'm looking for. |
Hi, I'm new to unit testing and I was wondering how to get svelte-jester working with i18n and the router.
When I run my test I get this error.
And the router error is..
The text was updated successfully, but these errors were encountered: