Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MaxKless
Copy link
Collaborator

@MaxKless MaxKless commented Apr 13, 2022

DEPENDS ON #3256 !! -> merged

What 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

Please provide a screenshot of this feature before and after your code changes, if applicable.

Other information:

@netlify
Copy link

netlify bot commented Apr 13, 2022

Deploy Preview for formly-dev ready!

Name Link
🔨 Latest commit 5919b1e
🔍 Latest deploy log https://app.netlify.com/sites/formly-dev/deploys/6256c91dcb5b260008dfdedf
😎 Deploy Preview https://deploy-preview-3271--formly-dev.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Apr 13, 2022

Deploy Preview for formly-dev ready!

Name Link
🔨 Latest commit 9c9551c
🔍 Latest deploy log https://app.netlify.com/sites/formly-dev/deploys/62e287daba733b000a39373e
😎 Deploy Preview https://deploy-preview-3271--formly-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@MaxKless
Copy link
Collaborator Author

Any thoughts on this, @aitboudad ?

Copy link
Member

@aitboudad aitboudad left a 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.

@MaxKless
Copy link
Collaborator Author

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 FormlyModule or just add another way?

@aitboudad
Copy link
Member

Makes sense, but do you want to replace the current way using the FormlyModule or just add another way?

For now just add another way, later we may deprecate the FormlyModule way.

@MaxKless
Copy link
Collaborator Author

MaxKless commented Jul 28, 2022

Okay, I added a way to declare presets through the FormlyPresetModule.
The demo component test isn't really necessary anymore because it's now forRoot instead of forTesting.

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...

@aitboudad
Copy link
Member

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...

Not related to this issue but it should work now.

image

@aitboudad
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants