Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use NO_ERRORS_SCHEMA and CUSTOM_ELEMENTS_SCHEMA?

Tags:

When we have to use NO_ERRORS_SCHEMA and CUSTOM_ELEMENTS_SCHEMA in Angular?

What do they mean? Is it config for CSS styles?

like image 277
OPV Avatar asked Nov 04 '19 18:11

OPV


People also ask

What is the use of Custom_elements_schema?

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.

What is the use of schemas No_errors_schema?

This schema allows you to ignore the errors related to any unknown elements or properties in a template.


1 Answers

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 .

like image 68
Wandrille Avatar answered Sep 30 '22 18:09

Wandrille