jeudi 28 janvier 2016

Unit tests failing "TypeError: Cannot read property 'element' of undefined" when using md-icon

I have an angular app (using AngularAMD/RequireJS) and I'm converting the design to use angular-material. I have a toolbar directive that has md-icon using md-svg-src.

Trouble running the toolbar-directive_test.js file.

At first it kept complaining "Unresolve GET request images/icon.svg". I resolved in the test setup using:

$httpBackend.whenGET(/\.svg$/).respond('');

Now if I run that test file using fdescribe(...) all the tests pass.

But if I run all my app tests (without fdescribe on that toolbar test file), they are somehow failing because of the md-icons. The error I get, which appears on another test file:

TypeError: Cannot read property 'element' of undefined

The stack-trace does not give any guidance on what is causing it. Only mentions angular-mocks.js, and then exits around the any random assertion on this test file where the error is showing. And if I xdescribe this file which is showing the element of undefined error, the next test file is failing with this error instead.

If I use xdescribe on toolbar-directive_test.js file (the one which has the md-icon), all the tests pass.

And if I run all tests including the toolbar-directive_test.js file, but I remove all the md-icon instances from its template, again all the tests are passing.

I have tried including ngMaterial-mocks package in my tests, and that doesn't do anything. But in general, I'm not using that package (but I am using ngMocks).

Any suggestions on how to debug this?

Aucun commentaire:

Enregistrer un commentaire