Skip to content

Component unit test is broken once added ng material #10950

@xhe

Description

@xhe

Bug, feature request, or proposal:

Unit failure, suggestion required

I am using angular material in the component template, such as

<mat-list role="list">
    <mat-list-item role="listitem">
        <div class='title'>
            <h3 mat-header color="primary">Loign (admin/admin or user/user)</h3>
        </div>

Then in my component unit test,

describe('LoginComponent', ()=>{

    let component:LoginComponent;
    let fixture:ComponentFixture<LoginComponent>;

    beforeEach(async()=>{
        TestBed.configureTestingModule({
            declarations:[LoginComponent]
        }).compileComponents();
    });

    beforeEach(() => {
        fixture = TestBed.createComponent(LoginComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

But immediately, the uni test is broken like below:

  [ERROR ->]<mat-list-item role="listitem">
	        <button (click)="login()" mat-raised-button color="primary"  "): ng:///DynamicTestModule/LoginComponent.html@23:4
	'mat-list' is not a known element:
	1. If 'mat-list' is an Angular component, then verify that it is part of this module.
	2. If 'mat-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

I tried to follow the instruction into ng_module, but useless, test is still broken.

Please help to suggest how to get rid of this error?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions