When we have to use NO_ERRORS_SCHEMA and CUSTOM_ELEMENTS_SCHEMA in Angular?
What do they mean? Is it config for CSS styles?
CUSTOM_ELEMENTS_SCHEMAlinkDefines a schema that allows an NgModule to contain the following: Non-Angular elements named with dash case ( - ). Element properties named with dash case ( - ). Dash case is the naming convention for custom elements.
This schema allows you to ignore the errors related to any unknown elements or properties in a template.
In your tests, when you define your TestBed
, you need to import or declare all the dependencies of your component.
BUT sometimes, it can be really annoying and long to write it, when your tests aren't on this particular child components.
This is the case where you can use NO_ERRORS_SCHEMA
. It will ignore all the errors saying that it doesn't know the child component <some-child>...</some-child>
.
But keep in mind that it's not a good practice to use NO_ERRORS_SCHEMA
. As an alternative, you can create your own mock of component or use this library ng-mocks which is very helpful.
CUSTOM_ELEMENTS_SCHEMA
is less permissive .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With