question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[md-menu][bug] Tests crash in MdMenu.ngOnDestroy

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

The test should work

What is the current behavior?

Tests on a component that uses MdMenu crash in MdMenu.ngOnDestroy, with error “Cannot read property ‘unsubscribe’ of undefined

        TypeError: Cannot read property 'unsubscribe' of undefined
            at MdMenu.ngOnDestroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/material/menu/menu-directive.js:44:0 <- src/test.ts:41822:30)
            at Wrapper_MdMenu.ngOnDestroy (/MdMenuModule/MdMenu/wrapper.ngfactory.js:14:16)
            at CompiledTemplate.proxyViewClass.View_AppComponent0.destroyInternal (/DynamicTestModule/AppComponent/component.ngfactory.js:265:21)
            at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/view.js:143:0 <- src/test.ts:55639:14)
            at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/view.js:368:0 <- src/test.ts:55864:38)
            at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.destroyInternal (/DynamicTestModule/AppComponent/host.ngfactory.js:33:19)
            at CompiledTemplate.proxyViewClass.AppView.destroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/view.js:143:0 <- src/test.ts:55639:14)
            at CompiledTemplate.proxyViewClass.DebugAppView.destroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/view.js:368:0 <- src/test.ts:55864:38)
            at CompiledTemplate.proxyViewClass.AppView.detachAndDestroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/view.js:130:0 <- src/test.ts:55626:14)
            at ComponentRef_.destroy (webpack:///C:/Users/User/git/training/material2-menu-test/~/@angular/core/src/linker/component_factory.js:121:51 <- src/test.ts:25170:70)

What are the steps to reproduce?

From this github repo: https://github.com/pchiquet/material2-menu-test

or manually:

  • ng new test-project
  • Setup Material2
  • Add a md-menu in src/app/app.component.html
  • launch test: ng test

What is the use-case or motivation for changing an existing behavior?

Testing apps with md-menu

Which versions of Angular, Material, OS, browsers are affected?

  • angular-cli 1.0.0-beta.20 (angular 2.1)
  • angular/material 2.0.0-alpha.10

Is there anything else we should know?

github repo to reproduce the issue : https://github.com/pchiquet/material2-menu-test

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
Headcultcommented, Jan 13, 2017

Found another workaround to fix this issue. Added fixture.detectChanges(); to my tests and all the tests passed! Not sure if this is the permanent fix for this or not.

3reactions
tydanielsoncommented, Jan 27, 2017

Adding fixture.detectChanges() didn’t work for me, but @shaxxx solutions to the compiled js did.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found