-
Notifications
You must be signed in to change notification settings - Fork 313
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
feat: add automatic mock for angular entities (#2908) #2953
base: main
Are you sure you want to change the base?
Conversation
26f4a39
to
39f1670
Compare
@ahnpnl Hi! I've been working on it, and I was wondering what the best way to test it would be. Do you think I should test it in the examples projects or somewhere else? I think it should tested for every supported Angular version. |
Hi, about this, I think we should have
|
@@ -1,7 +1,7 @@ | |||
semi: true | |||
printWidth: 120 | |||
singleQuote: true | |||
tabWidth: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you pls revert this?
@@ -111,7 +111,7 @@ | |||
"github-files-fetcher": "^1.6.0", | |||
"glob": "^10.4.5", | |||
"husky": "^9.1.7", | |||
"jest": "^29.7.0", | |||
"jest": "^30.0.0-alpha.7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only available in Jest 30, would you pls change merge target branch of this repo to next
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides, there are other Jest deps which need to be bumped together too. I think making a separate commit or PR to support Jest 30 first is necessary before this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I described it in the TODO section.
@@ -1,5 +1,6 @@ | |||
require('zone.js'); | |||
require('zone.js/testing'); | |||
require('../mock-transformer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not everyone would want this enabled by default, we should provide a flag to enable it via options provided in
const setupZoneTestEnv = (options) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides, this file is only for testbed setup, we shouldn’t add mock here. It’s better that we provide a utility function which can be imported in a Jest setup file which is owned by the users.
For example
// my-setup-test-file.ts
import { setupAutoMockForComp } from ‘jest-preset-angular’
Or any names which fit the purpose :)
@@ -1,3 +1,5 @@ | |||
require('../mock-transformer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment like we have in zone
Another thing is about documentation for this new feature, potentially a new file in https://github.com/thymikee/jest-preset-angular/tree/main/website/docs/guides |
Summary
Currently, to mock Angular components, services, pipes, directives, and modules, we need to manually create stubs for them. This PR introduces a new way to automatically mock them. The process can be simplified as follows:
Test plan
Does this PR introduce a breaking change?
TODO
Closes: #2908