Angular.js: Loading [email protected] causes TypeError

Created on 6 Feb 2016  路  13Comments  路  Source: angular/angular.js

Hello, I just tried updating to [email protected] and [email protected] and my tests are broken with this error:

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR: 'Unhandled promise rejection', 'TypeError: Attempted to assign to readonly property.
    Evaluating http://localhost:9876/static/base/public/jspm_packages/npm/[email protected]/angular-mocks.js
    Evaluating http://localhost:9876/static/base/public/jspm_packages/npm/[email protected]

I am using karma-jspm to run my unit tests, as described in this repo: https://github.com/gunnarlium/babel-jspm-karma-jasmine-istanbul

Used to work fine with [email protected].

more info bug

Most helpful comment

OK I figured it out. It's because my unit test must first load angular itself before trying to load angular-mocks. This is because I've switched to installing angular-mocks and angular from NPM instead of bower. For some reason, the package.json file of the angular-mocks package does not list any dependencies (not even Angular).

All 13 comments

It's impossible to tell what might be wrong without a way to reproduce it. Could you create a minimal reproduction of the issue ?

Closing due to lack of feedback.

Hey sorry I got really busy and wasn't able to provide any feedback about this issue for the last two weeks. I'm just picking this back up now, and it looks like even in Chrome, when the file angular-mocks.js tries to execute this code:

angular.mock = {};

I get the TypeError explained above.

OK I figured it out. It's because my unit test must first load angular itself before trying to load angular-mocks. This is because I've switched to installing angular-mocks and angular from NPM instead of bower. For some reason, the package.json file of the angular-mocks package does not list any dependencies (not even Angular).

@onlywei Thanks! I had the same import 'angular' issue that was giving me the same error!

i am facing the same problem.. how did you fix it. Thanks in adavance

@prasikumbhare I fixed it with the 1.5.6 release of Angular using this pull request: https://github.com/angular/bower-angular-mocks/pull/22

@onlywei Thanks so much.. in my case the problem was: i was using 'angularMocks' in 'paths' section of requireJS config But in 'shim' section i was referring it incorrectly as 'angular-mocks':

paths: {
'angular': 'war/lib/angularjs-1.5.5/angular.min',
'angularMocks': 'war/lib/angular-mocks/angular-mocks',
}
shim: {
'angular': {
exports: 'angular'
},
'angular-mocks': {
deps: ['angular'],
exports: "angular.mock"
},
}

Changing in the 'shim' to use 'angularMocks' fixed the problem..

@onlywei was stucks with this for hours, thanks for providing the solution.

@prasikumbhare What file did you put that json in?

@onlywei, I'm also facing the same issue, here could see the weird behaviour irrespective of the angular version, it's throwing error. Please check the following error log and let me know, if I'm missing anything.

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  TypeError: Attempted to assign to readonly property.
at app/bower_components/angular-mocks/angular-mocks.js:17

The following code is located at 17th line of the angular-mock
angular.mock = {};

Note:
I'm using angular version _1.4.8_, could see the same with 1.5.6

Same error as above, any word on a concrete solution for this?

Using angularJS 1.4.8, load angular.js before angular-mocks.js in the karma configuration file did the trick for me.

files: [
    //Closure library
    {pattern: 'node_modules/closure-library/closure/goog/base.js', watched: false, included: true, served: true},
    {pattern: './node_modules/closure-library/closure/goog/deps.js', watched: false, included: false, served: false},

    //Angular
    'node_modules/angular/angular.js',
    'node_modules/angular-mocks/angular-mocks.js',
Was this page helpful?
0 / 5 - 0 ratings