error: Failed: Template parse errors: 'mat-checkbox' is not a known element

26,199

You need to add imports array above declarations like this :

Add it like this :

import { MatCheckboxModule } from '@angular/material/checkbox';

And add imports array like this :

TestBed.configureTestingModule({
   imports: [
        MatCheckboxModule
   ],
   declarations: [AddAlarmsFormComponent]
})
Share:
26,199
Admin
Author by

Admin

Updated on January 29, 2020

Comments

  • Admin
    Admin over 4 years

    I create this code for testing my component.

    I tried this code:

    describe('Component: AddAlarms', () => {
        let component: AddAlarmsFormComponent;
        let fixture: ComponentFixture<AddAlarmsFormComponent>;
        beforeEach(() => {
            TestBed.configureTestingModule({
                declarations: [AddAlarmsFormComponent]
            });
            fixture = TestBed.createComponent(AddAlarmsFormComponent);
            component = fixture.componentInstance;
        });
    });
    

    when run ng test show this error:

    Failed: Template parse errors:
    'mat-checkbox' is not a known element:
    1. If 'mat-checkbox' is an Angular component, then verify that it is part of this module.
    2. If 'mat-checkbox' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
            </div>
            <div class="input-field col s2">
              [ERROR ->]<mat-checkbox class="example-margin" (click)="sortbydate()">Dates</mat-checkbox>
            </div>
         "): ng:///DynamicTestModule/NotificationsComponent.html@12:10
    

    I verify my module.ts and it's ok. So, I have this:

    import {MatCheckboxModule} from '@angular/material/checkbox';
    

    Can you tell me, what is the problem?

  • Admin
    Admin almost 6 years
    I decided on both, even on the module and in spec.ts But nothing happens
  • Edgar Quintero
    Edgar Quintero about 5 years
    The angular example code doesn't even have this, man their documentation is really sub par.