0
votes

I am getting following error message when unit test angular app

Can't bind to 'consoleMessages' since it isn't a known property of 'app-console'.

  1. If 'app-console' is an Angular component and it has 'consoleMessages' input, then verify that it is part of this module.
  2. If 'app-console' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
  <br>
     <app-console [ERROR ->][consoleMessages]="consoleMessages"></app-console>
      </div>"): ng:///DynamicTestModule/EntitlementCreateComponent.html@135:15
      'app-console' is not a known element:



TestBed.configureTestingModule({
   imports:[HttpClientTestingModule,RouterTestingModule,FormsModule,ReactiveFormsModule],
   declarations: [EntitlementCreateComponent,NGXSpinner],
   //schemas: [ NO_ERRORS_SCHEMA] //Note schemas is commenented
      })
1
schemas: [ CUSTOM_ELEMENTS_SCHEMA] adding this error disappears but I want to know why this error appearskaransys

1 Answers

1
votes

The reason why you are getting the error is because you are referencing the consoleMessages property of your app-console custom element. And the angular compiler can't find that property.

The CUSTOM_ELEMENTS_SCHEMA defines a schema that contains custom elements that are non-angular. So, by adding that schema, you are telling angular to ignore type checking on that element. It's probably not what you want.

My guess is that one of several things are going on:

  1. consoleMessages property is not defined as a public property on the AppConsole class.
  2. You have not configured AppConsole correctly in your test harness. Are you module in your test harness?