Angular Library : Material Menu : Error: Export of name 'matMenu' not found

Viewed 3108

I'm working on an Angular Library, I have this simple menu :

<mat-menu #menu="matMenu" yPosition="below" style="margin-top: 45px;">
    <button style="outline: none;" *ngFor='let button of card?.overflowmenu?.buttons' mat-menu-item
            class="header-menu-item">
        {{button.text}}
    </button>
</mat-menu>

And the module looks like this.

import { NgModule } from '@angular/core';
import { CardComponent } from './card.component';
import { MatMenuModule } from '@angular/material/menu';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  declarations: [CardComponent],
  imports: [
    BrowserModule,
    CommonModule,
    BrowserAnimationsModule,
    MatMenuModule,
  ],
  exports: []
})
export class CardModule { }

When I do : $ng test @libraryname.

I get the error: Error: Export of name 'matMenu' not found!

Is there something I'm missing to import when building an Angular library?

1 Answers

Your test needs to import the module as well - so you need

import { MatMenuModule } from '@angular/material/menu';

in your .spec.ts file's imports, and then

    TestBed.configureTestingModule({
      declarations: [YourComponent],
      imports: [
        NoopAnimationsModule,
        LayoutModule,
...
        MatMenuModule,
      ]
    }).compileComponents();

in your test file

Related