-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Error when running tests with Jest #22
Comments
|
I quickly checked with default angular tests settings (karma), and it does not throw any error. Maybe it's related to incorrect test configs in jest? |
It could be. The reproduction project uses default Jest settings, so I'll have to dig deeper to see whether it's config related. I was also trying to solve the circular dependency to see if that would help but haven't used much time on it yet. Will try to look at it during the weekend. |
@shhdharmen Different bundler will result in different output. We've often seen similar issues when people moved from webpack to esbuild. |
@JeanMeche I understand. I do not have much expertise in writing test cases, so I would rely on community inputs for this bug. And I also think this is not a bug, but a discussion. What do you think? @dzhavat I quickly tested with angular team's jest builder, and it worked fine there, too. In your repo, I followed below steps:
"test": {
"builder": "@angular-devkit/build-angular:jest", // 👈
"options": {
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "tsconfig.spec.json"
}
}
|
@shhdharmen you're right, it works with Angular's Jest builder by making the above adjustments ... buuut I also get a nice warning in the console 🙃
If the repo contains a custom Jest config, I get even more warnings. So while the Jest builder is there ... it's not yet ready for prime time. Note: The reason it works is because Angular is executing Jest with experimental ESM support. I just tried commenting out the Do you think it would be possible to remove the circular dependency? |
I got some time at work to look at the circular dependency to see if I can contribute to the project with a fix or a way around it. After using a few hours on it, I must acknowledge that it's not that simple as I had hoped for because I don't know the code that well, and the fix is not a "move this small function to another file". So I found another solution and that is to mock the module import using Jest's The config was as easy as // jest.config.ts
...
moduleNameMapper: {
'@ngxpert/hot-toast': 'path/to/custom/mock',
}, This was enough for the tests to start running again. It's not the best solution because we'll miss some other features but it's good enough in our case. We can still test the notifications using e2e tests if we have to. |
Same issue here, mocking it for now |
# [3.1.0-beta.3](v3.1.0-beta.2...v3.1.0-beta.3) (2024-12-10) ### Bug Fixes * use inject function instead of decorator ([9b63e61](9b63e61)), closes [#22](#22)
🎉 This issue has been resolved in version 3.1.0-beta.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [3.1.1-beta.1](v3.1.0...v3.1.1-beta.1) (2024-12-10) ### Bug Fixes * use inject function instead of decorator ([9b63e61](9b63e61)), closes [#22](#22)
🎉 This issue has been resolved in version 3.1.1-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [3.1.1](v3.1.0...v3.1.1) (2024-12-10) ### Bug Fixes * use inject function instead of decorator ([9b63e61](9b63e61)), closes [#22](#22)
🎉 This issue has been resolved in version 3.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hey,
the library looks great and I just tried it in a project! Works fantastic at run-time but I'm getting errors when running the tests with Jest.
I'm submitting a...
Current behavior
Getting the following error
Expected behavior
Tests run without error.
Note: Found a similar error in another repo. Maybe the fix is similar as well 🤔 valor-software/ng2-charts#1354
Minimal reproduction of the problem with instructions
npm install
npm run test
HotToastService
inapp.component.ts
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: