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
Allow demo component tests and update FormlyPresetModule.forTesting #3271
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for formly-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for formly-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Any thoughts on this, @aitboudad ? |
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.
instead of making it for testing purpose only, I'd prefer to provide a way to define presets
through FormlyPresetModule
. For naming we could use forRoot
or withConfig
.
Makes sense, but do you want to replace the current way using the |
For now just add another way, later we may deprecate the |
Okay, I added a way to declare presets through the I still think it could be useful though, so just let me know what you think, @aitboudad. Also, is there anything I can do about the failing tests? I can't see the netflify logs so no idea what's going on there... |
Could you please update the preset section as well https://github.com/ngx-formly/ngx-formly/blob/main/docs/formly-field-presets.md#defining-a-preset |
DEPENDS ON #3256 !!-> mergedWhat is the current behavior? (You can also link to an open issue here)
Currently, formly provides great test tooling to make writing jest tests for custom formly components (types, wrappers, extensions) easier.
However, testing formly from the outside (so components in an angular app that use formly) is not considered a lot.
What is the new behavior (if this is a feature change)?
This PR updates the jest config so that it is possible to write tests for demo components, which are "outside" components from a formly perspective. This means that functionality regarding testing can be written and tested right inside formly.
It also introduces a test for the preset example, in which the new
FormlyPresetModule.forTesting
method is used.I came to this idea because I had trouble writing clean unit tests in my app that uses formly. I ended up writing my own testing module to import in jest tests. When I built the preset module, I knew there was going to be some trouble with testing it but I had nowhere in the formly repo to fix and verify this problem. Now this is possible.
Please check if the PR fulfills these requirements
npm run build
produced a successful build. (Unit testing can be done by runningnpm test
;)npm run lint
to do this.npm run build
will fail if there are files not linted.)Please provide a screenshot of this feature before and after your code changes, if applicable.
Other information: