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

Make Unsupported CVA message more specific #3341

Closed
gregkaczan opened this issue Aug 17, 2022 · 4 comments · Fixed by #3383
Closed

Make Unsupported CVA message more specific #3341

gregkaczan opened this issue Aug 17, 2022 · 4 comments · Fixed by #3383

Comments

@gregkaczan
Copy link

gregkaczan commented Aug 17, 2022

Currently when CVA on which ngMocks.change/touch is run, tests whether callback function exists within the component. Those need to have very specific names. Like one of:

const keys = ['onChange', '_onChange', 'changeFn', '_onChangeCallback', 'onModelChange'];

Would be good to extend the generic error message thrown to include those as its not obvious just from the error message below why exactly is certain CVA unsupported.

throw new Error('Unsupported type of ControlValueAccessor');

Proposal:
Unsupported type of ControlValueAccessor: CVA component is missing required onChange callback. Was looking for either of these: ${keys.join()}

Obviously similar for touch.

@satanTime
Copy link
Member

Hi @GrzegorzKaczan,

thanks for the request.

Could you explain your use-case? Normally, as a developer you will be using onChange, but some libs and core use different methods which are covered by keys.

@gregkaczan
Copy link
Author

Sure.

Our internal framework that has few custom CVAs had a different pattern for the onChange callback, namely using onChangeClb, something that is not covered by keys and correctly throws an error. But with messy ng stacktrace and having the lib minified in the browser, seeing that message when testing does not tell You much, it is really hard to figure it out without actually reading unminified ngMocks code. There are many different aspects to CVA that could make it not a recognizable component for ngMocks, like using properties instead of functions, using ngModel injectors, and doing custom CVA with proxy pattern. Literally yesterday I was clueless why isn't it being recognized as proper CVA while all our forms rely on this component and all works fine otherwise.

@satanTime
Copy link
Member

I see. That makes sense. I'll update the error message with next release.

@satanTime
Copy link
Member

v14.2.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

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

Successfully merging a pull request may close this issue.

2 participants