Components: md-menu template parsing fail while unit testing

Created on 12 Apr 2017  Â·  13Comments  Â·  Source: angular/components

Hi I get following errors when run unit tests over my app.

Failed: Uncaught (in promise): Error: Template parse errors:
There is no directive with "exportAs" set to "mdMenu" ("
more_vert

]#menu="mdMenu">

]#menu="mdMenu">

Angular: 4.0.1
Angular Material: 2.0.0-beta.3
OS: Win7 x64
Browser: latest stable Chrome

cannot reproduce

Most helpful comment

Hi I get following error
There is no directive with "exportAs" set to "mdMenu"
2.0.0-beta.11

All 13 comments

Can you post the unit test? This seems like you might have a syntax error in your own code.

It fail in - on create test so if it is syntax error something must change in beta3 cause before my test passing without any problems.

My menu which I'm creating:

      <button md-icon-button [mdMenuTriggerFor]="menu">
        <md-icon>more_vert</md-icon>
      </button>
      <md-menu #menu="mdMenu">
        <button id="edit" md-menu-item routerLink="edit/{{user.id}}">
          <md-icon>edit</md-icon>
          <span>Edit</span>
        </button>
        <button id="account" md-menu-item routerLink="/accounts/{{user.id}}">
          <md-icon>account_balance_wallet</md-icon>
          <span>Account</span>
        </button>
      </md-menu>

Failing unit test(btw it's from parent component):

  it('should create', () => {
    expect(component).toBeTruthy();
  });

In regards thanks for help!

The menu hasn't really changed in beta 3. My guess is that it might be down to the update to Angular 4. I tried out your template and it seems fine, though.

Another cause could be that you haven't imported the MdMenuModule into your test module.

Closing this since we can't reproduce it; feel free to re-open if you have more information.

@jelbourn, I want to confirm:
should imports be done like this:

import { MaterialModule} from '@angular/material';

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [
        MaterialModule
    ]
  })
}));

or do all components need to be imported like this:

import { MdProgressSpinnerModule} from '@angular/material';

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [
        MdProgressSpinnerModule
    ]
  })
}));

Either case all my test seem to fail when they use material components.

@tmburnell the second option.

Hi I get following error
There is no directive with "exportAs" set to "mdMenu"
2.0.0-beta.11

@danieldflrss updating the angular version to 4.4.3 solved the issue for me.

tanks @raghavendar-ts

@raghavendar-ts which angular package did you update to 4.4.3? angular/core, angular/common, or?

@sdanieru npm update -D && npm update -S solve my problems

I updated the following angular modules to 4.4.3 which solved the issue.

"@angular/animations": "4.4.3",
"@angular/common": "4.4.3",
"@angular/compiler": "4.4.3",
"@angular/core": "4.4.3",
"@angular/forms": "4.4.3",
"@angular/http": "4.4.3",
"@angular/platform-browser": "4.4.3",
"@angular/platform-browser-dynamic": "4.4.3",
"@angular/router": "4.4.3",
"@angular/upgrade": "4.4.3"

Checkout the change log
https://github.com/angular/material2/blob/master/CHANGELOG.md

  • Angular Material now requires Angular 4.4.3 or greater

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
Virus-free.
www.avast.com
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Sep 28, 2017 at 8:48 PM, Franck notifications@github.com wrote:

@sdanieru https://github.com/sdanieru npm update -D && npm update -S
solve my problems

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/angular/material2/issues/4050#issuecomment-332869906,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AE3YQxF4a09eQwZ0WIW5RXn4yrzdvizjks5sm7jbgaJpZM4M7Jc5
.

--
Raghavendar T S
www.teknosrc.com

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xtianus79 picture xtianus79  Â·  3Comments

vitaly-t picture vitaly-t  Â·  3Comments

kara picture kara  Â·  3Comments

LoganDupont picture LoganDupont  Â·  3Comments

crutchcorn picture crutchcorn  Â·  3Comments