Allow demo component tests and update FormlyPresetModule.forTesting #3271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: