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

1.6.2 - mocking $window in unit tests throws undefined is not an object (evaluating '$window.angular.callbacks') #15685

Closed
@mattlewis92

Description

@mattlewis92

Note: for support questions, please use one of these channels: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports.

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

What is the current behavior?
1.6.2 only - if you mock the $window object in tests angular throws the error

undefined is not an object (evaluating '$window.angular.callbacks')

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).

Mock out the $window like so:

let $window;

beforeEach(angular.mock.module('myModule', $provide => {
    $window = {
      innerHeight: 100
    };
    $provide.constant('$window', $window);
}));

Any tests that you try to run after this throw that error. This was working OK in < 1.6.2.

What is the expected behavior?
It should be possible to mock out the $window object in tests.

What is the motivation / use case for changing the behavior?
$window exists so that you can mock it.

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.
1.6.2 only

Other information (e.g. stacktraces, related issues, suggestions how to fix)
I guess it was caused by this commit: 0377c6f

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions