Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Regression in ng-mock generates unworkably meaningless messages for unit testing on Webkit browsers. #4994

Closed
wizardwerdna opened this issue Nov 17, 2013 · 2 comments

Comments

@wizardwerdna
Copy link
Contributor

The current version of ngMock is breaking, generating meaningless error messages for tests when used with some Webkit-based browsers, although it is working fine in Chrome. For example:

 1 'use strict';
 2 describe('failure in ng-mocks', function(){
 3   beforeEach(inject(function($compile, $rootScope){
 4     $compile(
 5       '<div ng-include="\'nofilehere\'"></div>'
 6     )($rootScope);
 7     $rootScope.$digest();
 8   }));
 9   it('displayed by example', function(){
10     console.log('hello, world');
11   });
12 });

The test properly fails at line 5 because "nofilehere" does not exist and has not been inserted into the template cache. We get a very meaningful message when driving this with karma under Chrome (and it worked until recently on most browsers):

Error: Unexpected request: GET nofilehere
(stack trace)

At this time, however, PhantomJS and Chrome instead give the following:

TypeError: Attempted to assign to readonly property.
    at workFn (/Users/werdna/errors/app/bower_components/angular-mocks/angular-mocks.js:2122)

This occurs because the error is at one time caught at line 2122 in the following angular-mocks code:

2116       for(var i = 0, ii = blockFns.length; i < ii; i++) {
2117         try {
2118           /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */
2119           injector.invoke(blockFns[i] || angular.noop, this);
2120           /* jshint +W040 */
2121         } catch (e) {
2122           if(e.stack && errorForStack) e.stack +=  '\n' + errorForStack.stack;
2123           throw e;
2124         } finally {
2125           errorForStack = null;
2126         }
2127       }

and some recent versions of Webkit Error messages now have read-only 'stack' properties. (Both configurable and writable are false.) Thus, line 2122 fails because e.stack is unwritable, and the new TypeError is thrown, losing the old stack when the TypeError is created.

Unfortunately, I couldn't think of any other way to rethrow an Error instance with a modified stack string, and was unable to come up with a meaningful pull request.

Unfortunately, this makes Unit testing difficult, and whatever benefit derives from inserting the errorForStack message is lost to me now.

Any thoughts?

@wizardwerdna
Copy link
Contributor Author

Here is a pull request fixing the problem. #5047

@btford
Copy link
Contributor

btford commented Mar 5, 2014

Looks like this is fixed by #5047. Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants