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

Test fails in IE: TypeError: Unable to get property 'documentMode' of undefined or null reference #4931

Closed
evgenyneu opened this issue Nov 13, 2013 · 6 comments

Comments

@evgenyneu
Copy link

Hi, I get my test failing in all IE versions. AngularJS version is 1.2.1 stable.

Error message is

TypeError: Unable to get property 'documentMode' of undefined or null reference.
angular.js:12590:7

Here is a plunk: http://plnkr.co/edit/bwum5GA1HOm0xrzYHlBi?p=preview

It fails only when I use $interpolate service AND when I mock services in test:

beforeEach(function() {
  angular.mock.module(function($provide) {
    $provide.value('$window', {});
    return null;
  });
}

Thank you

@IgorMinar
Copy link
Contributor

what version of IE is this?

@evgenyneu
Copy link
Author

@IgorMinar IE 8, 9 and 10.

@tbosch
Copy link
Contributor

tbosch commented Nov 20, 2013

With my new VM I can verify this also for IE11. Looking into this...

@tbosch
Copy link
Contributor

tbosch commented Nov 20, 2013

When you replace $window in your tests, the $document service returns an empty jquery object, as it tries to read $window.document. And then we have the $sce provider which contains the following code:

    // Prereq: Ensure that we're not running in IE8 quirks mode.  In that mode, IE allows
    // the "expression(javascript expression)" syntax which is insecure.
    if (enabled && msie) {
      var documentMode = $document[0].documentMode;
      if (documentMode !== undefined && documentMode < 8) {
        throw $sceMinErr('iequirks',
          'Strict Contextual Escaping does not support Internet Explorer version < 9 in quirks ' +
          'mode.  You can fix this by adding the text <!doctype html> to the top of your HTML ' +
          'document.  See http://docs.angularjs.org/api/ng.$sce for more information.');
      }
    }

To make your test happy, also provide $document:

beforeEach(function() {
  angular.mock.module(function($provide) {
    $provide.value('$window', {});
    $provide.value('$document', [{}]);    
    return null;
  });
}

Here is an updated punk: http://plnkr.co/edit/DxlTmMddbiHT2xPifrwD?p=preview

@tbosch
Copy link
Contributor

tbosch commented Nov 20, 2013

The code for $sce is doing feature detection. I would suggest moving the documentMode extraction into $sniffer, as we already do some tests against documentMode there and also provide the msie flag there. This would also make the tests for $sce nicer, as they could then just override $sniffer instead of setting the msie flag using $window.msie = ....

For future reader: Setting the msie flag using window.msie only works within the testsuite of Angular as our tests don't use the surrounding function closure of Angular and therefore have access to all of the internals of Angular...

Will create a PR shortly.

@evgenyneu
Copy link
Author

@tbosch thanks for looking in to that and for the detailed explanation. Now it makes sense to me. Looking forward to your pull request being merged to master. Thanks!

tbosch added a commit to tbosch/angular.js that referenced this issue Nov 20, 2013
Also adds `$sniffer.msieDocumentMode` property.

Fixes angular#4931.
@tbosch tbosch closed this as completed in ec3c4f9 Nov 20, 2013
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants