"Cannot instantiate cyclic dependency! NgControl"
See original GitHub issueAfter struggling for a couple of days with an error on tests when upgrading our project to Angular 10 (and shallow-render), I’ve found the solution in your playground project on stackblitz.
.provideMock({
provide: NG_VALUE_ACCESSOR,
useClass: DefaultValueAccessor,
multi: true,
});
This was what was missing from our tests so we don’t get an error like:
Error: Template parse errors:
Cannot instantiate cyclic dependency! NgControl (
[ERROR ->]<nz-select #selector
(ngModelChange)="onChange($event)"
(nzBlur)="onTouched()"
"): ng:///ShallowTestModule/FormControlImplementationEaseComponent.html@1:2
at syntaxError (/home/ztp/repos/bee/packages/compiler/src/util.ts:108:17)
at TemplateParser.Object.<anonymous>.TemplateParser.parse (/home/ztp/repos/bee/packages/compiler/src/template_parser/template_parser.ts:108:13)
I’ve forked your playground project, and upgraded shallow-render to v10.2.0: https://stackblitz.com/edit/github-mpmyc2?file=examples/test.spec.ts
If I delete that provideMock()
code from your example/component-with-forms.spec.ts
still works, but not when the ngModel
is applied to a component that implements ControlValueAccessor
, like on the file “test.spec.ts” on my stackblitz instance.
I’m not understanding this completly so several doubts come across my mind:
- Is
DefaultValueAccessor
provided by Angular by default onNG_VALUE_ACCESSOR
? - Should this
provideMock()
code above be added by shallow-render automatically besidesneverMocking(NG_VALUE_ACCESSOR)
.
Not sure even if these doubts make sense… Hope you got a more clear view on this. Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
Just published an official release 10.2.1 with this fix!
I just published a beta release (v10.2.1-0), give this a go and let me know how it goes. If it works out, I’ll make this the next full release.
npm i -D shallow-render@10.2.1-0