Skip to content

Usage of toHaveFormValues with reactive forms without name attribute #162

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

Closed
rafaelss95 opened this issue Nov 6, 2020 · 4 comments
Closed

Comments

@rafaelss95
Copy link
Contributor

Generally when we use reactive forms, we specify formControlName, but not name. Would be possible to override toHaveFormValues in order to avoid specify name for every form field?

@timdeschryver
Copy link
Member

I'm not sure...
I would say not to override it, since it's part of jest-dom.

We could create a new matcher in our jest-utils package.
Do you think think the implementation would be an easy one?
I also don't know how this reacts to nested/dynamic forms.

An easier approach would be to create an angular directive that sets the name?

@rafaelss95
Copy link
Contributor Author

Hmm, I'm not also sure what the ideal solution would be, because as you said, this would be tricky for nested forms.. so the implementation would not be really easy.

I guess the directive solves the problem. Do you think it would be interesting to document that toHaveFormValues only works with Reactive Forms if you specify "name" or by creating a directive that replicates the formControlName as name?

@timdeschryver
Copy link
Member

Yes, if you've lost time to investigate this problem I'm sure that adding it to the docs will help future devs 🙂
I'm just not sure where to add it, perhaps create a FAQ section?

@timdeschryver
Copy link
Member

Closing this because #165 is merged.
Feel free to add an additional note about having a directive.

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

No branches or pull requests

2 participants