mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Add missing angular.mock.createMockWindow (removed in
0dd062231a), that the docs tests were
using.
29 lines
895 B
JavaScript
29 lines
895 B
JavaScript
var createMockWindow = function() {
|
|
var mockWindow = {};
|
|
var setTimeoutQueue = [];
|
|
|
|
mockWindow.location = window.location;
|
|
mockWindow.document = window.document;
|
|
mockWindow.getComputedStyle = angular.bind(window, window.getComputedStyle);
|
|
mockWindow.scrollTo = angular.bind(window, window.scrollTo);
|
|
mockWindow.navigator = window.navigator;
|
|
mockWindow.setTimeout = function(fn, delay) {
|
|
setTimeoutQueue.push({fn: fn, delay: delay});
|
|
};
|
|
mockWindow.setTimeout.queue = setTimeoutQueue;
|
|
mockWindow.setTimeout.expect = function(delay) {
|
|
if (setTimeoutQueue.length > 0) {
|
|
return {
|
|
process: function() {
|
|
var tick = setTimeoutQueue.shift();
|
|
expect(tick.delay).toEqual(delay);
|
|
tick.fn();
|
|
}
|
|
};
|
|
} else {
|
|
expect('SetTimoutQueue empty. Expecting delay of ').toEqual(delay);
|
|
}
|
|
};
|
|
|
|
return mockWindow;
|
|
};
|