-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasmine-mockdate.js
199 lines (154 loc) · 4.99 KB
/
jasmine-mockdate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("jasmine"));
else if(typeof define === 'function' && define.amd)
define(["jasmine"], factory);
else if(typeof exports === 'object')
exports["jasmineMockDate"] = factory(require("jasmine"));
else
root["jasmineMockDate"] = factory(root["jasmine"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
var jasmine = __webpack_require__(1);
var jasmineMockDate = __webpack_require__(2);
var MockDate = __webpack_require__(3);
exports = module.exports = jasmineMockDate;
exports.MockDate = MockDate;
jasmine.Clock.useMockDate = function() {
if (jasmineMockDate.isInstalled()) return;
var spec = jasmine.getEnv().currentSpec;
spec.after(jasmineMockDate.uninstall);
jasmineMockDate.install();
};
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {var MockDate = __webpack_require__(3);
var Date = global.Date
var jasmineMockDate = module.exports;
jasmineMockDate.real = Date;
jasmineMockDate.install = function() {
MockDate.baseTime = new Date().getTime();
global.Date = MockDate;
};
jasmineMockDate.uninstall = function() {
jasmineMockDate.assertInstalled();
MockDate.baseTime = 0;
global.Date = jasmineMockDate.real;
};
jasmineMockDate.isInstalled = function() {
return global.Date === MockDate;
};
jasmineMockDate.assertInstalled = function() {
if (!jasmineMockDate.isInstalled()) {
throw new Error("MockDate is not installed, use jasmine.Clock.useMockDate()");
}
};
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/**
* Adopted from Sinon.JS
* https://github.com/cjohansen/Sinon.JS
* Copyright (c) 2010-2013 Christian Johansen
*/
var jasmine = __webpack_require__(1);
// keep the native Date
var Date = global.Date;
module.exports = MockDate;
function MockDate(year, month, day, hour, minute, second, millisecond) {
// called without new operator
if (!(this instanceof MockDate)) {
return Date();
}
switch (arguments.length) {
case 0:
// create mocked date
return new Date(now());
case 1:
return new Date(year);
case 2:
return new Date(year, month);
case 3:
return new Date(year, month, day);
case 4:
return new Date(year, month, day, hour);
case 5:
return new Date(year, month, day, hour, minute);
case 6:
return new Date(year, month, day, hour, minute, second);
default:
return new Date(year, month, day, hour, minute, second, millisecond);
}
}
MockDate.baseTime = 0;
function now() {
return MockDate.baseTime + jasmine.Clock.defaultFakeTimer.nowMillis;
}
if (Date.now) {
MockDate.now = now;
} else {
delete MockDate.now;
}
if (Date.toSource) {
MockDate.toSource = function toSource() {
return Date.toSource();
};
} else {
delete MockDate.toSource;
}
MockDate.toString = function toString() {
return Date.toString();
};
MockDate.prototype = Date.prototype;
MockDate.parse = Date.parse;
MockDate.UTC = Date.UTC;
MockDate.prototype.toUTCString = Date.prototype.toUTCString;
for (var prop in Date) {
if (Date.hasOwnProperty(prop)) {
MockDate[prop] = Date[prop];
}
}
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }
/******/ ])
});
;