Embed module in karma test in Angular 1.5

I am trying to upgrade my Angular application from 1.3.x to 1.5.1. I have a set of tests that all worked perfectly with Karma + PhantomJS when I was in version 1.3.x of Angular, however, after I updated all my tests, you failed. It seems that the way I introduced modules into unit tests no longer works.

This does not work in 1.5:

'use strict'
 App = null

 fdescribe 'App Model', ->
   beforeEach module('MyAngularApp')

   beforeEach inject ($injector)->
     App = $injector.get('App')

 it 'should exist', ->
   console.log 'App:', App
   expect(App).toBeDefined()

I also tried to inject the following

 beforeEach inject ($injector, _App_)->
   App = _App_

but my application model is still not being introduced.

I was looking at the documentation on AngularJS 1.5.1, but I did not see any changes that I need to make with the injector.

In Angular 1.5.x, how can I correctly insert a model into my unit tests?

+4
source share
2

, , , angular-mocks . , AngularJS, Karma PhantomJS, angular-mock.js , karma.conf.js, . , PhantomJS , .

, , , , Chrome ( PhantomJS 2), :

Error: [$injector:modulerr] Failed to instantiate module ng due to:
Error: [$injector:modulerr] Failed to instantiate module ngLocale due to:
RangeError: Maximum call stack size exceeded

: https://github.com/angular/angular.js/issues/11303

+2
beforeEach(inject(function ($injector) {
      loginService = $injector.get('LoginService');
    }));
-1

All Articles