karma tests failing -- can't resolve javascript module (angular-moment/moment.js) I've added

2,737 views
Skip to first unread message

Michael Murray

unread,
May 5, 2014, 1:55:35 PM5/5/14
to mea...@googlegroups.com
Hello - I've added angular-moment directive and filters for moment.js to my meanjs app and it works fine at app runtime (I can use the moment directives), but when I run tests it fails my karma test run because it cannot resolve the angularMoment module dependency in the test context... ideas?
I saw this Stack Overflow article which seems to be my problem, but looking at config/config.js I don't see how to add angular-moment and moment.js to my test dependencies.  Obviously I'm missing something.

To add to my application I added to applicationModuleVendorDependencies in config.js

var applicationModuleVendorDependencies = ['ngResource', 'ngCookies', 'ngAnimate', 'ngTouch', 'ngSanitize', 'ui.router', 'ui.bootstrap', 'ui.utils', 'angularMoment'];

and then to my template in app/views/layout.server.view.html (although I maybe shouldn't have to do this?)

<!-- moment support -->
<script src="lib/moment/moment.js"></script>
    <script src="lib/angular-moment/angular-moment.js"></script>

The server mocha tests all pass (and as I said I can use moment in my app) but I'm not injecting angularMoment into the app when in karma test context... unfortunately it then fails in a way that is both spectacular and useless :}.  There's probably something simple I need to add to make this resolution work for test runs but can't see it... TIA for any help - Michael

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.14 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket ZBPZSdPrNn12QjTpb_uj with id 88347748
PhantomJS 1.9.7 (Mac OS X) ArticlesController $scope.find() should create an array with at least one article object fetched from XHR FAILED
Error: [$injector:modulerr] Failed to instantiate module opinulate due to:
Error: [$injector:modulerr] Failed to instantiate module angularMoment due to:
Error: [$injector:nomod] Module 'angularMoment' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
   at /Users/michael/projects/test/public/lib/angular/angular.js:1613
   at ensure (/Users/michael/projects/test/public/lib/angular/angular.js:1535)
   at module (/Users/michael/projects/test/public/lib/angular/angular.js:1823)
   at /Users/mmurray/projects/opinulate/public/lib/angular/angular.js:3781
http://errors.angularjs.org/1.2.16/$injector/modulerr?p0=angularMoment&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'angularMoment'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.16%2F%24injector%2Fnomod%3Fp0%3DangularMoment%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1613%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1535)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1823)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A3781

Michael Murray

unread,
May 5, 2014, 2:02:58 PM5/5/14
to mea...@googlegroups.com
(self-answer <blush/> :)) it was pretty simple; I just had to add the following lines to module.exports js array in all.js:

'public/lib/moment/moment.js',
'public/lib/angular-moment/angular-moment.js'

Michael

Alex Suttmiller

unread,
May 6, 2014, 8:45:36 AM5/6/14
to mea...@googlegroups.com
That got me before as well :)
Reply all
Reply to author
Forward
0 new messages