Angular.js: angular-mocks.js v1.6.3 fails when to run it via Jasmine

Created on 9 Mar 2017  路  12Comments  路  Source: angular/angular.js

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Currently, angular-mocks.js file crashes when to run it via Jasmine with the following error:

TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })') at
.PATH_TO_PROJECT\tools\gruntnode_modules\angular-mocks\angular-mocks.js:800

Due to this, Jasmine can't load tests which use 'module' or 'inject' variables.

What is the expected behavior?
It is expected to have a possibility to use angular-mocks.js file and its data in Jasmine tests.

Which versions of AngularJS, and which browser / OS are affected by this issue? Did this work in previous versions of AngularJS? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
"angular-mocks": "1.6.3",
"grunt-contrib-jasmine": "^1.1.0"

Yes, it works fine with versions lower than 1.6.3.

Most helpful comment

I think that means you are running angular (ng) with a version below 1.6.3 which is not supported. The different angularJS modules must run with the same version.

All 12 comments

I'm having exactly the same error.

I think that means you are running angular (ng) with a version below 1.6.3 which is not supported. The different angularJS modules must run with the same version.

Yes, they are different. The angular version that I'm currently working on is 1.5.8.

This is incorrect. You cannot use angular 1.5.8 with angular-mocks 1.6.3. The versions must match to the patch version. Did you use angular 1.5.8 with angular-mocks 1.6.2 before? Why?

We got burned by this yesterday as well. As best I can tell, npm install picks up 1.6.3 if you've got your angular-mocks dependency set to ^1.5.8 which seems incorrect. If you're shrinkwrapping your dependencies and not your devDependencies you'll end up with angular 1.5.8 and angular-mocks 1.6.3 which are not compatible.

Here's the relevant excerpts from our project's package.json:

"devDependencies": { "angular-mocks": "^1.5.8",

"dependencies": { "angular": "^1.5.8",

Since AngularJS does not strictly follow semver (i.e. we do make breaking changes between minor versions) you must be more strict in your dependency ranges, e.g. 1.5.x or >=1.5.3 <1.6.

I'm getting this error Running Angular 1.6.4 and angular-mocks 1.6.4

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
    .info({ angularVersion: '1.6.4' })')
  at /Users/diegodesouza/Documents/Work/Healthcast/healthcast-app-v2/node_modules/angular-mocks/angular-mocks.js:800

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: [$injector:nomod] Module 'hcApp.home' 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.
  http://errors.angularjs.org/1.5.3/$injector/nomod?p0=hcApp.home
  at /Users/diegodesouza/Documents/Work/Healthcast/healthcast-app-v2/www/lib/ionic/js/ionic.bundle.js:15411

@diegodesouza, you are probably not v1.6.4 of angular.js. Make sure all you angular modules are on the same version.

@gkalpak does karma have to match angular and angular-mocks as well? because the my version for karma is different, 1.6.0.
my package.json

  "devDependencies": {
    "angular-mocks": "^1.6.4"
}

my bower.json

  "devDependencies": {
    "ionic": "driftyco/ionic-bower#1.3.3"
  },
  "resolutions": {
    "angular": "^1.6.4",
    "angular-animate": "^1.6.4",
    "angular-sanitize": "^1.6.4",
    "angular-ui-router": "^0.2.13"
  },
  "dependencies": {
    "angular": "^1.6.4",
    "angular-animate": "^1.6.4",
    "angular-sanitize": "^1.6.4",
    "angular-ui-router": "^0.2.13"
  }
}

Though I noticed that driftyco/ionic-bower is using a different version of angular, and we import the bundle into our Index.html. Could that be it? if so, other than forking the repo, is there a way to update the dependencies locally?

No, karma doesn't have to match (it's not an angular module).
Yes, the problem is that ionic brings in an older version. I am not sure what is the best way to address this problem; this is a question for the ionic folks. (Make sure to search through the existing issues first, since this is likely to have come up before.)

I have same problem now could @diegodesouza could you tell me what have you did to solve it

Hi @tomavic, i no longer have access that repo i was working on, and don't recall what worked for me. My guess is that the angular versions need to match. As mentioned above. Sorry i couldn't be more of a help

Was this page helpful?
0 / 5 - 0 ratings