Search code examples
angularunit-testingtestbed

Angular:Why NO_ERRORS_SCHEMA does not work for attribute?


I'm writing my first Angular tests and having a problem here. I'm testing a component, which has a custom attribute in it

<ng-container *isGranted="admin">
...
</ng-container>

Official documentation says

The NO_ERRORS_SCHEMA tells the Angular compiler to ignore unrecognized elements and attributes.

So I added the following to my TestBed config:

schemas: [NO_ERRORS_SCHEMA]

But still, I'm getting an error:

Property binding isGranted not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations

Where am I wrong? I do not want to test how isGranted behaves, I just want to check that a correct value was assigned to it.


Solution

  • You are using directive, while NO_ERROR_SCHEMA is to ignore custom components. See github when error is thrown with proper exception saying that you need to include directives

    Property binding ${prop.name} not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".