1 | (function (global, factory) {
|
---|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/testing'), require('@angular/core/testing'), require('rxjs/operators'), require('rxjs'), require('@angular/cdk/keycodes')) :
|
---|
3 | typeof define === 'function' && define.amd ? define('@angular/cdk/testing/testbed', ['exports', '@angular/cdk/testing', '@angular/core/testing', 'rxjs/operators', 'rxjs', '@angular/cdk/keycodes'], factory) :
|
---|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.testing = global.ng.cdk.testing || {}, global.ng.cdk.testing.testbed = {}), global.ng.cdk.testing, global.ng.core.testing, global.rxjs.operators, global.rxjs, global.ng.cdk.keycodes));
|
---|
5 | }(this, (function (exports, testing, testing$1, operators, rxjs, keyCodes) { 'use strict';
|
---|
6 |
|
---|
7 | function _interopNamespace(e) {
|
---|
8 | if (e && e.__esModule) return e;
|
---|
9 | var n = Object.create(null);
|
---|
10 | if (e) {
|
---|
11 | Object.keys(e).forEach(function (k) {
|
---|
12 | if (k !== 'default') {
|
---|
13 | var d = Object.getOwnPropertyDescriptor(e, k);
|
---|
14 | Object.defineProperty(n, k, d.get ? d : {
|
---|
15 | enumerable: true,
|
---|
16 | get: function () {
|
---|
17 | return e[k];
|
---|
18 | }
|
---|
19 | });
|
---|
20 | }
|
---|
21 | });
|
---|
22 | }
|
---|
23 | n['default'] = e;
|
---|
24 | return Object.freeze(n);
|
---|
25 | }
|
---|
26 |
|
---|
27 | var keyCodes__namespace = /*#__PURE__*/_interopNamespace(keyCodes);
|
---|
28 |
|
---|
29 | /*! *****************************************************************************
|
---|
30 | Copyright (c) Microsoft Corporation.
|
---|
31 |
|
---|
32 | Permission to use, copy, modify, and/or distribute this software for any
|
---|
33 | purpose with or without fee is hereby granted.
|
---|
34 |
|
---|
35 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
---|
36 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
---|
37 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
---|
38 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
---|
39 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
---|
40 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
---|
41 | PERFORMANCE OF THIS SOFTWARE.
|
---|
42 | ***************************************************************************** */
|
---|
43 | /* global Reflect, Promise */
|
---|
44 | var extendStatics = function (d, b) {
|
---|
45 | extendStatics = Object.setPrototypeOf ||
|
---|
46 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
---|
47 | function (d, b) { for (var p in b)
|
---|
48 | if (Object.prototype.hasOwnProperty.call(b, p))
|
---|
49 | d[p] = b[p]; };
|
---|
50 | return extendStatics(d, b);
|
---|
51 | };
|
---|
52 | function __extends(d, b) {
|
---|
53 | if (typeof b !== "function" && b !== null)
|
---|
54 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
---|
55 | extendStatics(d, b);
|
---|
56 | function __() { this.constructor = d; }
|
---|
57 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
58 | }
|
---|
59 | var __assign = function () {
|
---|
60 | __assign = Object.assign || function __assign(t) {
|
---|
61 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
---|
62 | s = arguments[i];
|
---|
63 | for (var p in s)
|
---|
64 | if (Object.prototype.hasOwnProperty.call(s, p))
|
---|
65 | t[p] = s[p];
|
---|
66 | }
|
---|
67 | return t;
|
---|
68 | };
|
---|
69 | return __assign.apply(this, arguments);
|
---|
70 | };
|
---|
71 | function __rest(s, e) {
|
---|
72 | var t = {};
|
---|
73 | for (var p in s)
|
---|
74 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
---|
75 | t[p] = s[p];
|
---|
76 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
---|
77 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
---|
78 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
---|
79 | t[p[i]] = s[p[i]];
|
---|
80 | }
|
---|
81 | return t;
|
---|
82 | }
|
---|
83 | function __decorate(decorators, target, key, desc) {
|
---|
84 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
---|
85 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
---|
86 | r = Reflect.decorate(decorators, target, key, desc);
|
---|
87 | else
|
---|
88 | for (var i = decorators.length - 1; i >= 0; i--)
|
---|
89 | if (d = decorators[i])
|
---|
90 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
---|
91 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
---|
92 | }
|
---|
93 | function __param(paramIndex, decorator) {
|
---|
94 | return function (target, key) { decorator(target, key, paramIndex); };
|
---|
95 | }
|
---|
96 | function __metadata(metadataKey, metadataValue) {
|
---|
97 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
---|
98 | return Reflect.metadata(metadataKey, metadataValue);
|
---|
99 | }
|
---|
100 | function __awaiter(thisArg, _arguments, P, generator) {
|
---|
101 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
---|
102 | return new (P || (P = Promise))(function (resolve, reject) {
|
---|
103 | function fulfilled(value) { try {
|
---|
104 | step(generator.next(value));
|
---|
105 | }
|
---|
106 | catch (e) {
|
---|
107 | reject(e);
|
---|
108 | } }
|
---|
109 | function rejected(value) { try {
|
---|
110 | step(generator["throw"](value));
|
---|
111 | }
|
---|
112 | catch (e) {
|
---|
113 | reject(e);
|
---|
114 | } }
|
---|
115 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
---|
116 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
---|
117 | });
|
---|
118 | }
|
---|
119 | function __generator(thisArg, body) {
|
---|
120 | var _ = { label: 0, sent: function () { if (t[0] & 1)
|
---|
121 | throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
---|
122 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
---|
123 | function verb(n) { return function (v) { return step([n, v]); }; }
|
---|
124 | function step(op) {
|
---|
125 | if (f)
|
---|
126 | throw new TypeError("Generator is already executing.");
|
---|
127 | while (_)
|
---|
128 | try {
|
---|
129 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
---|
130 | return t;
|
---|
131 | if (y = 0, t)
|
---|
132 | op = [op[0] & 2, t.value];
|
---|
133 | switch (op[0]) {
|
---|
134 | case 0:
|
---|
135 | case 1:
|
---|
136 | t = op;
|
---|
137 | break;
|
---|
138 | case 4:
|
---|
139 | _.label++;
|
---|
140 | return { value: op[1], done: false };
|
---|
141 | case 5:
|
---|
142 | _.label++;
|
---|
143 | y = op[1];
|
---|
144 | op = [0];
|
---|
145 | continue;
|
---|
146 | case 7:
|
---|
147 | op = _.ops.pop();
|
---|
148 | _.trys.pop();
|
---|
149 | continue;
|
---|
150 | default:
|
---|
151 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
---|
152 | _ = 0;
|
---|
153 | continue;
|
---|
154 | }
|
---|
155 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
---|
156 | _.label = op[1];
|
---|
157 | break;
|
---|
158 | }
|
---|
159 | if (op[0] === 6 && _.label < t[1]) {
|
---|
160 | _.label = t[1];
|
---|
161 | t = op;
|
---|
162 | break;
|
---|
163 | }
|
---|
164 | if (t && _.label < t[2]) {
|
---|
165 | _.label = t[2];
|
---|
166 | _.ops.push(op);
|
---|
167 | break;
|
---|
168 | }
|
---|
169 | if (t[2])
|
---|
170 | _.ops.pop();
|
---|
171 | _.trys.pop();
|
---|
172 | continue;
|
---|
173 | }
|
---|
174 | op = body.call(thisArg, _);
|
---|
175 | }
|
---|
176 | catch (e) {
|
---|
177 | op = [6, e];
|
---|
178 | y = 0;
|
---|
179 | }
|
---|
180 | finally {
|
---|
181 | f = t = 0;
|
---|
182 | }
|
---|
183 | if (op[0] & 5)
|
---|
184 | throw op[1];
|
---|
185 | return { value: op[0] ? op[1] : void 0, done: true };
|
---|
186 | }
|
---|
187 | }
|
---|
188 | var __createBinding = Object.create ? (function (o, m, k, k2) {
|
---|
189 | if (k2 === undefined)
|
---|
190 | k2 = k;
|
---|
191 | Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
---|
192 | }) : (function (o, m, k, k2) {
|
---|
193 | if (k2 === undefined)
|
---|
194 | k2 = k;
|
---|
195 | o[k2] = m[k];
|
---|
196 | });
|
---|
197 | function __exportStar(m, o) {
|
---|
198 | for (var p in m)
|
---|
199 | if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
---|
200 | __createBinding(o, m, p);
|
---|
201 | }
|
---|
202 | function __values(o) {
|
---|
203 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
---|
204 | if (m)
|
---|
205 | return m.call(o);
|
---|
206 | if (o && typeof o.length === "number")
|
---|
207 | return {
|
---|
208 | next: function () {
|
---|
209 | if (o && i >= o.length)
|
---|
210 | o = void 0;
|
---|
211 | return { value: o && o[i++], done: !o };
|
---|
212 | }
|
---|
213 | };
|
---|
214 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
---|
215 | }
|
---|
216 | function __read(o, n) {
|
---|
217 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
218 | if (!m)
|
---|
219 | return o;
|
---|
220 | var i = m.call(o), r, ar = [], e;
|
---|
221 | try {
|
---|
222 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
---|
223 | ar.push(r.value);
|
---|
224 | }
|
---|
225 | catch (error) {
|
---|
226 | e = { error: error };
|
---|
227 | }
|
---|
228 | finally {
|
---|
229 | try {
|
---|
230 | if (r && !r.done && (m = i["return"]))
|
---|
231 | m.call(i);
|
---|
232 | }
|
---|
233 | finally {
|
---|
234 | if (e)
|
---|
235 | throw e.error;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | return ar;
|
---|
239 | }
|
---|
240 | /** @deprecated */
|
---|
241 | function __spread() {
|
---|
242 | for (var ar = [], i = 0; i < arguments.length; i++)
|
---|
243 | ar = ar.concat(__read(arguments[i]));
|
---|
244 | return ar;
|
---|
245 | }
|
---|
246 | /** @deprecated */
|
---|
247 | function __spreadArrays() {
|
---|
248 | for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
---|
249 | s += arguments[i].length;
|
---|
250 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
---|
251 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
---|
252 | r[k] = a[j];
|
---|
253 | return r;
|
---|
254 | }
|
---|
255 | function __spreadArray(to, from, pack) {
|
---|
256 | if (pack || arguments.length === 2)
|
---|
257 | for (var i = 0, l = from.length, ar; i < l; i++) {
|
---|
258 | if (ar || !(i in from)) {
|
---|
259 | if (!ar)
|
---|
260 | ar = Array.prototype.slice.call(from, 0, i);
|
---|
261 | ar[i] = from[i];
|
---|
262 | }
|
---|
263 | }
|
---|
264 | return to.concat(ar || from);
|
---|
265 | }
|
---|
266 | function __await(v) {
|
---|
267 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
---|
268 | }
|
---|
269 | function __asyncGenerator(thisArg, _arguments, generator) {
|
---|
270 | if (!Symbol.asyncIterator)
|
---|
271 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
272 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
---|
273 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
---|
274 | function verb(n) { if (g[n])
|
---|
275 | i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
---|
276 | function resume(n, v) { try {
|
---|
277 | step(g[n](v));
|
---|
278 | }
|
---|
279 | catch (e) {
|
---|
280 | settle(q[0][3], e);
|
---|
281 | } }
|
---|
282 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
---|
283 | function fulfill(value) { resume("next", value); }
|
---|
284 | function reject(value) { resume("throw", value); }
|
---|
285 | function settle(f, v) { if (f(v), q.shift(), q.length)
|
---|
286 | resume(q[0][0], q[0][1]); }
|
---|
287 | }
|
---|
288 | function __asyncDelegator(o) {
|
---|
289 | var i, p;
|
---|
290 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
---|
291 | function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
---|
292 | }
|
---|
293 | function __asyncValues(o) {
|
---|
294 | if (!Symbol.asyncIterator)
|
---|
295 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
296 | var m = o[Symbol.asyncIterator], i;
|
---|
297 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
---|
298 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
---|
299 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
---|
300 | }
|
---|
301 | function __makeTemplateObject(cooked, raw) {
|
---|
302 | if (Object.defineProperty) {
|
---|
303 | Object.defineProperty(cooked, "raw", { value: raw });
|
---|
304 | }
|
---|
305 | else {
|
---|
306 | cooked.raw = raw;
|
---|
307 | }
|
---|
308 | return cooked;
|
---|
309 | }
|
---|
310 | ;
|
---|
311 | var __setModuleDefault = Object.create ? (function (o, v) {
|
---|
312 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
313 | }) : function (o, v) {
|
---|
314 | o["default"] = v;
|
---|
315 | };
|
---|
316 | function __importStar(mod) {
|
---|
317 | if (mod && mod.__esModule)
|
---|
318 | return mod;
|
---|
319 | var result = {};
|
---|
320 | if (mod != null)
|
---|
321 | for (var k in mod)
|
---|
322 | if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
---|
323 | __createBinding(result, mod, k);
|
---|
324 | __setModuleDefault(result, mod);
|
---|
325 | return result;
|
---|
326 | }
|
---|
327 | function __importDefault(mod) {
|
---|
328 | return (mod && mod.__esModule) ? mod : { default: mod };
|
---|
329 | }
|
---|
330 | function __classPrivateFieldGet(receiver, state, kind, f) {
|
---|
331 | if (kind === "a" && !f)
|
---|
332 | throw new TypeError("Private accessor was defined without a getter");
|
---|
333 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
334 | throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
---|
335 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
---|
336 | }
|
---|
337 | function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
---|
338 | if (kind === "m")
|
---|
339 | throw new TypeError("Private method is not writable");
|
---|
340 | if (kind === "a" && !f)
|
---|
341 | throw new TypeError("Private accessor was defined without a setter");
|
---|
342 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
343 | throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
---|
344 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
---|
345 | }
|
---|
346 |
|
---|
347 | /** Unique symbol that is used to patch a property to a proxy zone. */
|
---|
348 | var stateObservableSymbol = Symbol('ProxyZone_PATCHED#stateObservable');
|
---|
349 | /**
|
---|
350 | * Interceptor that can be set up in a `ProxyZone` instance. The interceptor
|
---|
351 | * will keep track of the task state and emit whenever the state changes.
|
---|
352 | *
|
---|
353 | * This serves as a workaround for https://github.com/angular/angular/issues/32896.
|
---|
354 | */
|
---|
355 | var TaskStateZoneInterceptor = /** @class */ (function () {
|
---|
356 | function TaskStateZoneInterceptor(_lastState) {
|
---|
357 | this._lastState = _lastState;
|
---|
358 | /** Subject that can be used to emit a new state change. */
|
---|
359 | this._stateSubject = new rxjs.BehaviorSubject(this._lastState ? this._getTaskStateFromInternalZoneState(this._lastState) : { stable: true });
|
---|
360 | /** Public observable that emits whenever the task state changes. */
|
---|
361 | this.state = this._stateSubject;
|
---|
362 | }
|
---|
363 | /** This will be called whenever the task state changes in the intercepted zone. */
|
---|
364 | TaskStateZoneInterceptor.prototype.onHasTask = function (delegate, current, target, hasTaskState) {
|
---|
365 | if (current === target) {
|
---|
366 | this._stateSubject.next(this._getTaskStateFromInternalZoneState(hasTaskState));
|
---|
367 | }
|
---|
368 | };
|
---|
369 | /** Gets the task state from the internal ZoneJS task state. */
|
---|
370 | TaskStateZoneInterceptor.prototype._getTaskStateFromInternalZoneState = function (state) {
|
---|
371 | return { stable: !state.macroTask && !state.microTask };
|
---|
372 | };
|
---|
373 | /**
|
---|
374 | * Sets up the custom task state Zone interceptor in the `ProxyZone`. Throws if
|
---|
375 | * no `ProxyZone` could be found.
|
---|
376 | * @returns an observable that emits whenever the task state changes.
|
---|
377 | */
|
---|
378 | TaskStateZoneInterceptor.setup = function () {
|
---|
379 | if (Zone === undefined) {
|
---|
380 | throw Error('Could not find ZoneJS. For test harnesses running in TestBed, ' +
|
---|
381 | 'ZoneJS needs to be installed.');
|
---|
382 | }
|
---|
383 | // tslint:disable-next-line:variable-name
|
---|
384 | var ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
---|
385 | // If there is no "ProxyZoneSpec" installed, we throw an error and recommend
|
---|
386 | // setting up the proxy zone by pulling in the testing bundle.
|
---|
387 | if (!ProxyZoneSpec) {
|
---|
388 | throw Error('ProxyZoneSpec is needed for the test harnesses but could not be found. ' +
|
---|
389 | 'Please make sure that your environment includes zone.js/dist/zone-testing.js');
|
---|
390 | }
|
---|
391 | // Ensure that there is a proxy zone instance set up, and get
|
---|
392 | // a reference to the instance if present.
|
---|
393 | var zoneSpec = ProxyZoneSpec.assertPresent();
|
---|
394 | // If there already is a delegate registered in the proxy zone, and it
|
---|
395 | // is type of the custom task state interceptor, we just use that state
|
---|
396 | // observable. This allows us to only intercept Zone once per test
|
---|
397 | // (similar to how `fakeAsync` or `async` work).
|
---|
398 | if (zoneSpec[stateObservableSymbol]) {
|
---|
399 | return zoneSpec[stateObservableSymbol];
|
---|
400 | }
|
---|
401 | // Since we intercept on environment creation and the fixture has been
|
---|
402 | // created before, we might have missed tasks scheduled before. Fortunately
|
---|
403 | // the proxy zone keeps track of the previous task state, so we can just pass
|
---|
404 | // this as initial state to the task zone interceptor.
|
---|
405 | var interceptor = new TaskStateZoneInterceptor(zoneSpec.lastTaskState);
|
---|
406 | var zoneSpecOnHasTask = zoneSpec.onHasTask.bind(zoneSpec);
|
---|
407 | // We setup the task state interceptor in the `ProxyZone`. Note that we cannot register
|
---|
408 | // the interceptor as a new proxy zone delegate because it would mean that other zone
|
---|
409 | // delegates (e.g. `FakeAsyncTestZone` or `AsyncTestZone`) can accidentally overwrite/disable
|
---|
410 | // our interceptor. Since we just intend to monitor the task state of the proxy zone, it is
|
---|
411 | // sufficient to just patch the proxy zone. This also avoids that we interfere with the task
|
---|
412 | // queue scheduling logic.
|
---|
413 | zoneSpec.onHasTask = function () {
|
---|
414 | var args = [];
|
---|
415 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
416 | args[_i] = arguments[_i];
|
---|
417 | }
|
---|
418 | zoneSpecOnHasTask.apply(void 0, __spreadArray([], __read(args)));
|
---|
419 | interceptor.onHasTask.apply(interceptor, __spreadArray([], __read(args)));
|
---|
420 | };
|
---|
421 | return zoneSpec[stateObservableSymbol] = interceptor.state;
|
---|
422 | };
|
---|
423 | return TaskStateZoneInterceptor;
|
---|
424 | }());
|
---|
425 |
|
---|
426 | /**
|
---|
427 | * @license
|
---|
428 | * Copyright Google LLC All Rights Reserved.
|
---|
429 | *
|
---|
430 | * Use of this source code is governed by an MIT-style license that can be
|
---|
431 | * found in the LICENSE file at https://angular.io/license
|
---|
432 | */
|
---|
433 | /** Used to generate unique IDs for events. */
|
---|
434 | var uniqueIds = 0;
|
---|
435 | /**
|
---|
436 | * Creates a browser MouseEvent with the specified options.
|
---|
437 | * @docs-private
|
---|
438 | */
|
---|
439 | function createMouseEvent(type, clientX, clientY, button, modifiers) {
|
---|
440 | if (clientX === void 0) { clientX = 0; }
|
---|
441 | if (clientY === void 0) { clientY = 0; }
|
---|
442 | if (button === void 0) { button = 0; }
|
---|
443 | if (modifiers === void 0) { modifiers = {}; }
|
---|
444 | var event = document.createEvent('MouseEvent');
|
---|
445 | var originalPreventDefault = event.preventDefault.bind(event);
|
---|
446 | // Note: We cannot determine the position of the mouse event based on the screen
|
---|
447 | // because the dimensions and position of the browser window are not available
|
---|
448 | // To provide reasonable `screenX` and `screenY` coordinates, we simply use the
|
---|
449 | // client coordinates as if the browser is opened in fullscreen.
|
---|
450 | var screenX = clientX;
|
---|
451 | var screenY = clientY;
|
---|
452 | event.initMouseEvent(type,
|
---|
453 | /* canBubble */ true,
|
---|
454 | /* cancelable */ true,
|
---|
455 | /* view */ window,
|
---|
456 | /* detail */ 0,
|
---|
457 | /* screenX */ screenX,
|
---|
458 | /* screenY */ screenY,
|
---|
459 | /* clientX */ clientX,
|
---|
460 | /* clientY */ clientY,
|
---|
461 | /* ctrlKey */ !!modifiers.control,
|
---|
462 | /* altKey */ !!modifiers.alt,
|
---|
463 | /* shiftKey */ !!modifiers.shift,
|
---|
464 | /* metaKey */ !!modifiers.meta,
|
---|
465 | /* button */ button,
|
---|
466 | /* relatedTarget */ null);
|
---|
467 | // `initMouseEvent` doesn't allow us to pass these properties into the constructor.
|
---|
468 | // Override them to 1, because they're used for fake screen reader event detection.
|
---|
469 | defineReadonlyEventProperty(event, 'buttons', 1);
|
---|
470 | defineReadonlyEventProperty(event, 'offsetX', 1);
|
---|
471 | defineReadonlyEventProperty(event, 'offsetY', 1);
|
---|
472 | // IE won't set `defaultPrevented` on synthetic events so we need to do it manually.
|
---|
473 | event.preventDefault = function () {
|
---|
474 | defineReadonlyEventProperty(event, 'defaultPrevented', true);
|
---|
475 | return originalPreventDefault();
|
---|
476 | };
|
---|
477 | return event;
|
---|
478 | }
|
---|
479 | /**
|
---|
480 | * Creates a browser `PointerEvent` with the specified options. Pointer events
|
---|
481 | * by default will appear as if they are the primary pointer of their type.
|
---|
482 | * https://www.w3.org/TR/pointerevents2/#dom-pointerevent-isprimary.
|
---|
483 | *
|
---|
484 | * For example, if pointer events for a multi-touch interaction are created, the non-primary
|
---|
485 | * pointer touches would need to be represented by non-primary pointer events.
|
---|
486 | *
|
---|
487 | * @docs-private
|
---|
488 | */
|
---|
489 | function createPointerEvent(type, clientX, clientY, options) {
|
---|
490 | if (clientX === void 0) { clientX = 0; }
|
---|
491 | if (clientY === void 0) { clientY = 0; }
|
---|
492 | if (options === void 0) { options = { isPrimary: true }; }
|
---|
493 | return new PointerEvent(type, Object.assign({ bubbles: true, cancelable: true, view: window, clientX: clientX, clientY: clientY }, options));
|
---|
494 | }
|
---|
495 | /**
|
---|
496 | * Creates a browser TouchEvent with the specified pointer coordinates.
|
---|
497 | * @docs-private
|
---|
498 | */
|
---|
499 | function createTouchEvent(type, pageX, pageY, clientX, clientY) {
|
---|
500 | if (pageX === void 0) { pageX = 0; }
|
---|
501 | if (pageY === void 0) { pageY = 0; }
|
---|
502 | if (clientX === void 0) { clientX = 0; }
|
---|
503 | if (clientY === void 0) { clientY = 0; }
|
---|
504 | // In favor of creating events that work for most of the browsers, the event is created
|
---|
505 | // as a basic UI Event. The necessary details for the event will be set manually.
|
---|
506 | var event = document.createEvent('UIEvent');
|
---|
507 | var touchDetails = { pageX: pageX, pageY: pageY, clientX: clientX, clientY: clientY, id: uniqueIds++ };
|
---|
508 | // TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
|
---|
509 | event.initUIEvent(type, true, true, window, 0);
|
---|
510 | // Most of the browsers don't have a "initTouchEvent" method that can be used to define
|
---|
511 | // the touch details.
|
---|
512 | defineReadonlyEventProperty(event, 'touches', [touchDetails]);
|
---|
513 | defineReadonlyEventProperty(event, 'targetTouches', [touchDetails]);
|
---|
514 | defineReadonlyEventProperty(event, 'changedTouches', [touchDetails]);
|
---|
515 | return event;
|
---|
516 | }
|
---|
517 | /**
|
---|
518 | * Creates a keyboard event with the specified key and modifiers.
|
---|
519 | * @docs-private
|
---|
520 | */
|
---|
521 | function createKeyboardEvent(type, keyCode, key, modifiers) {
|
---|
522 | if (keyCode === void 0) { keyCode = 0; }
|
---|
523 | if (key === void 0) { key = ''; }
|
---|
524 | if (modifiers === void 0) { modifiers = {}; }
|
---|
525 | var event = document.createEvent('KeyboardEvent');
|
---|
526 | var originalPreventDefault = event.preventDefault.bind(event);
|
---|
527 | // Firefox does not support `initKeyboardEvent`, but supports `initKeyEvent`.
|
---|
528 | // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent.
|
---|
529 | if (event.initKeyEvent !== undefined) {
|
---|
530 | event.initKeyEvent(type, true, true, window, modifiers.control, modifiers.alt, modifiers.shift, modifiers.meta, keyCode);
|
---|
531 | }
|
---|
532 | else {
|
---|
533 | // `initKeyboardEvent` expects to receive modifiers as a whitespace-delimited string
|
---|
534 | // See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
|
---|
535 | var modifiersList = '';
|
---|
536 | if (modifiers.control) {
|
---|
537 | modifiersList += 'Control ';
|
---|
538 | }
|
---|
539 | if (modifiers.alt) {
|
---|
540 | modifiersList += 'Alt ';
|
---|
541 | }
|
---|
542 | if (modifiers.shift) {
|
---|
543 | modifiersList += 'Shift ';
|
---|
544 | }
|
---|
545 | if (modifiers.meta) {
|
---|
546 | modifiersList += 'Meta ';
|
---|
547 | }
|
---|
548 | // TS3.6 removed the `initKeyboardEvent` method and suggested porting to
|
---|
549 | // `new KeyboardEvent()` constructor. We cannot use that as we support IE11.
|
---|
550 | // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent.
|
---|
551 | event.initKeyboardEvent(type, true, /* canBubble */ true, /* cancelable */ window, /* view */ 0, /* char */ key, /* key */ 0, /* location */ modifiersList.trim(), /* modifiersList */ false /* repeat */);
|
---|
552 | }
|
---|
553 | // Webkit Browsers don't set the keyCode when calling the init function.
|
---|
554 | // See related bug https://bugs.webkit.org/show_bug.cgi?id=16735
|
---|
555 | defineReadonlyEventProperty(event, 'keyCode', keyCode);
|
---|
556 | defineReadonlyEventProperty(event, 'key', key);
|
---|
557 | defineReadonlyEventProperty(event, 'ctrlKey', !!modifiers.control);
|
---|
558 | defineReadonlyEventProperty(event, 'altKey', !!modifiers.alt);
|
---|
559 | defineReadonlyEventProperty(event, 'shiftKey', !!modifiers.shift);
|
---|
560 | defineReadonlyEventProperty(event, 'metaKey', !!modifiers.meta);
|
---|
561 | // IE won't set `defaultPrevented` on synthetic events so we need to do it manually.
|
---|
562 | event.preventDefault = function () {
|
---|
563 | defineReadonlyEventProperty(event, 'defaultPrevented', true);
|
---|
564 | return originalPreventDefault();
|
---|
565 | };
|
---|
566 | return event;
|
---|
567 | }
|
---|
568 | /**
|
---|
569 | * Creates a fake event object with any desired event type.
|
---|
570 | * @docs-private
|
---|
571 | */
|
---|
572 | function createFakeEvent(type, canBubble, cancelable) {
|
---|
573 | if (canBubble === void 0) { canBubble = false; }
|
---|
574 | if (cancelable === void 0) { cancelable = true; }
|
---|
575 | var event = document.createEvent('Event');
|
---|
576 | event.initEvent(type, canBubble, cancelable);
|
---|
577 | return event;
|
---|
578 | }
|
---|
579 | /**
|
---|
580 | * Defines a readonly property on the given event object. Readonly properties on an event object
|
---|
581 | * are always set as configurable as that matches default readonly properties for DOM event objects.
|
---|
582 | */
|
---|
583 | function defineReadonlyEventProperty(event, propertyName, value) {
|
---|
584 | Object.defineProperty(event, propertyName, { get: function () { return value; }, configurable: true });
|
---|
585 | }
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * @license
|
---|
589 | * Copyright Google LLC All Rights Reserved.
|
---|
590 | *
|
---|
591 | * Use of this source code is governed by an MIT-style license that can be
|
---|
592 | * found in the LICENSE file at https://angular.io/license
|
---|
593 | */
|
---|
594 | /**
|
---|
595 | * Utility to dispatch any event on a Node.
|
---|
596 | * @docs-private
|
---|
597 | */
|
---|
598 | function dispatchEvent(node, event) {
|
---|
599 | node.dispatchEvent(event);
|
---|
600 | return event;
|
---|
601 | }
|
---|
602 | /**
|
---|
603 | * Shorthand to dispatch a fake event on a specified node.
|
---|
604 | * @docs-private
|
---|
605 | */
|
---|
606 | function dispatchFakeEvent(node, type, canBubble) {
|
---|
607 | return dispatchEvent(node, createFakeEvent(type, canBubble));
|
---|
608 | }
|
---|
609 | /**
|
---|
610 | * Shorthand to dispatch a keyboard event with a specified key code and
|
---|
611 | * optional modifiers.
|
---|
612 | * @docs-private
|
---|
613 | */
|
---|
614 | function dispatchKeyboardEvent(node, type, keyCode, key, modifiers) {
|
---|
615 | return dispatchEvent(node, createKeyboardEvent(type, keyCode, key, modifiers));
|
---|
616 | }
|
---|
617 | /**
|
---|
618 | * Shorthand to dispatch a mouse event on the specified coordinates.
|
---|
619 | * @docs-private
|
---|
620 | */
|
---|
621 | function dispatchMouseEvent(node, type, clientX, clientY, button, modifiers) {
|
---|
622 | if (clientX === void 0) { clientX = 0; }
|
---|
623 | if (clientY === void 0) { clientY = 0; }
|
---|
624 | return dispatchEvent(node, createMouseEvent(type, clientX, clientY, button, modifiers));
|
---|
625 | }
|
---|
626 | /**
|
---|
627 | * Shorthand to dispatch a pointer event on the specified coordinates.
|
---|
628 | * @docs-private
|
---|
629 | */
|
---|
630 | function dispatchPointerEvent(node, type, clientX, clientY, options) {
|
---|
631 | if (clientX === void 0) { clientX = 0; }
|
---|
632 | if (clientY === void 0) { clientY = 0; }
|
---|
633 | return dispatchEvent(node, createPointerEvent(type, clientX, clientY, options));
|
---|
634 | }
|
---|
635 | /**
|
---|
636 | * Shorthand to dispatch a touch event on the specified coordinates.
|
---|
637 | * @docs-private
|
---|
638 | */
|
---|
639 | function dispatchTouchEvent(node, type, pageX, pageY, clientX, clientY) {
|
---|
640 | if (pageX === void 0) { pageX = 0; }
|
---|
641 | if (pageY === void 0) { pageY = 0; }
|
---|
642 | if (clientX === void 0) { clientX = 0; }
|
---|
643 | if (clientY === void 0) { clientY = 0; }
|
---|
644 | return dispatchEvent(node, createTouchEvent(type, pageX, pageY, clientX, clientY));
|
---|
645 | }
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * @license
|
---|
649 | * Copyright Google LLC All Rights Reserved.
|
---|
650 | *
|
---|
651 | * Use of this source code is governed by an MIT-style license that can be
|
---|
652 | * found in the LICENSE file at https://angular.io/license
|
---|
653 | */
|
---|
654 | function triggerFocusChange(element, event) {
|
---|
655 | var eventFired = false;
|
---|
656 | var handler = function () { return eventFired = true; };
|
---|
657 | element.addEventListener(event, handler);
|
---|
658 | element[event]();
|
---|
659 | element.removeEventListener(event, handler);
|
---|
660 | if (!eventFired) {
|
---|
661 | dispatchFakeEvent(element, event);
|
---|
662 | }
|
---|
663 | }
|
---|
664 | /**
|
---|
665 | * Patches an elements focus and blur methods to emit events consistently and predictably.
|
---|
666 | * This is necessary, because some browsers, like IE11, will call the focus handlers asynchronously,
|
---|
667 | * while others won't fire them at all if the browser window is not focused.
|
---|
668 | * @docs-private
|
---|
669 | */
|
---|
670 | function patchElementFocus(element) {
|
---|
671 | element.focus = function () { return dispatchFakeEvent(element, 'focus'); };
|
---|
672 | element.blur = function () { return dispatchFakeEvent(element, 'blur'); };
|
---|
673 | }
|
---|
674 | /** @docs-private */
|
---|
675 | function triggerFocus(element) {
|
---|
676 | triggerFocusChange(element, 'focus');
|
---|
677 | }
|
---|
678 | /** @docs-private */
|
---|
679 | function triggerBlur(element) {
|
---|
680 | triggerFocusChange(element, 'blur');
|
---|
681 | }
|
---|
682 |
|
---|
683 | /** Input types for which the value can be entered incrementally. */
|
---|
684 | var incrementalInputTypes = new Set(['text', 'email', 'hidden', 'password', 'search', 'tel', 'url']);
|
---|
685 | /**
|
---|
686 | * Checks whether the given Element is a text input element.
|
---|
687 | * @docs-private
|
---|
688 | */
|
---|
689 | function isTextInput(element) {
|
---|
690 | var nodeName = element.nodeName.toLowerCase();
|
---|
691 | return nodeName === 'input' || nodeName === 'textarea';
|
---|
692 | }
|
---|
693 | function typeInElement(element) {
|
---|
694 | var e_1, _a;
|
---|
695 | var modifiersAndKeys = [];
|
---|
696 | for (var _i = 1; _i < arguments.length; _i++) {
|
---|
697 | modifiersAndKeys[_i - 1] = arguments[_i];
|
---|
698 | }
|
---|
699 | var first = modifiersAndKeys[0];
|
---|
700 | var modifiers;
|
---|
701 | var rest;
|
---|
702 | if (typeof first !== 'string' && first.keyCode === undefined && first.key === undefined) {
|
---|
703 | modifiers = first;
|
---|
704 | rest = modifiersAndKeys.slice(1);
|
---|
705 | }
|
---|
706 | else {
|
---|
707 | modifiers = {};
|
---|
708 | rest = modifiersAndKeys;
|
---|
709 | }
|
---|
710 | var isInput = isTextInput(element);
|
---|
711 | var inputType = element.getAttribute('type') || 'text';
|
---|
712 | var keys = rest
|
---|
713 | .map(function (k) { return typeof k === 'string' ?
|
---|
714 | k.split('').map(function (c) { return ({ keyCode: c.toUpperCase().charCodeAt(0), key: c }); }) : [k]; })
|
---|
715 | .reduce(function (arr, k) { return arr.concat(k); }, []);
|
---|
716 | // We simulate the user typing in a value by incrementally assigning the value below. The problem
|
---|
717 | // is that for some input types, the browser won't allow for an invalid value to be set via the
|
---|
718 | // `value` property which will always be the case when going character-by-character. If we detect
|
---|
719 | // such an input, we have to set the value all at once or listeners to the `input` event (e.g.
|
---|
720 | // the `ReactiveFormsModule` uses such an approach) won't receive the correct value.
|
---|
721 | var enterValueIncrementally = inputType === 'number' && keys.length > 0 ?
|
---|
722 | // The value can be set character by character in number inputs if it doesn't have any decimals.
|
---|
723 | keys.every(function (key) { return key.key !== '.' && key.keyCode !== keyCodes.PERIOD; }) :
|
---|
724 | incrementalInputTypes.has(inputType);
|
---|
725 | triggerFocus(element);
|
---|
726 | // When we aren't entering the value incrementally, assign it all at once ahead
|
---|
727 | // of time so that any listeners to the key events below will have access to it.
|
---|
728 | if (!enterValueIncrementally) {
|
---|
729 | element.value = keys.reduce(function (value, key) { return value + (key.key || ''); }, '');
|
---|
730 | }
|
---|
731 | try {
|
---|
732 | for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
---|
733 | var key = keys_1_1.value;
|
---|
734 | dispatchKeyboardEvent(element, 'keydown', key.keyCode, key.key, modifiers);
|
---|
735 | dispatchKeyboardEvent(element, 'keypress', key.keyCode, key.key, modifiers);
|
---|
736 | if (isInput && key.key && key.key.length === 1) {
|
---|
737 | if (enterValueIncrementally) {
|
---|
738 | element.value += key.key;
|
---|
739 | dispatchFakeEvent(element, 'input');
|
---|
740 | }
|
---|
741 | }
|
---|
742 | dispatchKeyboardEvent(element, 'keyup', key.keyCode, key.key, modifiers);
|
---|
743 | }
|
---|
744 | }
|
---|
745 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
---|
746 | finally {
|
---|
747 | try {
|
---|
748 | if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
---|
749 | }
|
---|
750 | finally { if (e_1) throw e_1.error; }
|
---|
751 | }
|
---|
752 | // Since we weren't dispatching `input` events while sending the keys, we have to do it now.
|
---|
753 | if (!enterValueIncrementally) {
|
---|
754 | dispatchFakeEvent(element, 'input');
|
---|
755 | }
|
---|
756 | }
|
---|
757 | /**
|
---|
758 | * Clears the text in an input or textarea element.
|
---|
759 | * @docs-private
|
---|
760 | */
|
---|
761 | function clearElement(element) {
|
---|
762 | triggerFocus(element);
|
---|
763 | element.value = '';
|
---|
764 | dispatchFakeEvent(element, 'input');
|
---|
765 | }
|
---|
766 |
|
---|
767 | /**
|
---|
768 | * @license
|
---|
769 | * Copyright Google LLC All Rights Reserved.
|
---|
770 | *
|
---|
771 | * Use of this source code is governed by an MIT-style license that can be
|
---|
772 | * found in the LICENSE file at https://angular.io/license
|
---|
773 | */
|
---|
774 |
|
---|
775 | var _a;
|
---|
776 | /** Maps `TestKey` constants to the `keyCode` and `key` values used by native browser events. */
|
---|
777 | var keyMap = (_a = {},
|
---|
778 | _a[testing.TestKey.BACKSPACE] = { keyCode: keyCodes__namespace.BACKSPACE, key: 'Backspace' },
|
---|
779 | _a[testing.TestKey.TAB] = { keyCode: keyCodes__namespace.TAB, key: 'Tab' },
|
---|
780 | _a[testing.TestKey.ENTER] = { keyCode: keyCodes__namespace.ENTER, key: 'Enter' },
|
---|
781 | _a[testing.TestKey.SHIFT] = { keyCode: keyCodes__namespace.SHIFT, key: 'Shift' },
|
---|
782 | _a[testing.TestKey.CONTROL] = { keyCode: keyCodes__namespace.CONTROL, key: 'Control' },
|
---|
783 | _a[testing.TestKey.ALT] = { keyCode: keyCodes__namespace.ALT, key: 'Alt' },
|
---|
784 | _a[testing.TestKey.ESCAPE] = { keyCode: keyCodes__namespace.ESCAPE, key: 'Escape' },
|
---|
785 | _a[testing.TestKey.PAGE_UP] = { keyCode: keyCodes__namespace.PAGE_UP, key: 'PageUp' },
|
---|
786 | _a[testing.TestKey.PAGE_DOWN] = { keyCode: keyCodes__namespace.PAGE_DOWN, key: 'PageDown' },
|
---|
787 | _a[testing.TestKey.END] = { keyCode: keyCodes__namespace.END, key: 'End' },
|
---|
788 | _a[testing.TestKey.HOME] = { keyCode: keyCodes__namespace.HOME, key: 'Home' },
|
---|
789 | _a[testing.TestKey.LEFT_ARROW] = { keyCode: keyCodes__namespace.LEFT_ARROW, key: 'ArrowLeft' },
|
---|
790 | _a[testing.TestKey.UP_ARROW] = { keyCode: keyCodes__namespace.UP_ARROW, key: 'ArrowUp' },
|
---|
791 | _a[testing.TestKey.RIGHT_ARROW] = { keyCode: keyCodes__namespace.RIGHT_ARROW, key: 'ArrowRight' },
|
---|
792 | _a[testing.TestKey.DOWN_ARROW] = { keyCode: keyCodes__namespace.DOWN_ARROW, key: 'ArrowDown' },
|
---|
793 | _a[testing.TestKey.INSERT] = { keyCode: keyCodes__namespace.INSERT, key: 'Insert' },
|
---|
794 | _a[testing.TestKey.DELETE] = { keyCode: keyCodes__namespace.DELETE, key: 'Delete' },
|
---|
795 | _a[testing.TestKey.F1] = { keyCode: keyCodes__namespace.F1, key: 'F1' },
|
---|
796 | _a[testing.TestKey.F2] = { keyCode: keyCodes__namespace.F2, key: 'F2' },
|
---|
797 | _a[testing.TestKey.F3] = { keyCode: keyCodes__namespace.F3, key: 'F3' },
|
---|
798 | _a[testing.TestKey.F4] = { keyCode: keyCodes__namespace.F4, key: 'F4' },
|
---|
799 | _a[testing.TestKey.F5] = { keyCode: keyCodes__namespace.F5, key: 'F5' },
|
---|
800 | _a[testing.TestKey.F6] = { keyCode: keyCodes__namespace.F6, key: 'F6' },
|
---|
801 | _a[testing.TestKey.F7] = { keyCode: keyCodes__namespace.F7, key: 'F7' },
|
---|
802 | _a[testing.TestKey.F8] = { keyCode: keyCodes__namespace.F8, key: 'F8' },
|
---|
803 | _a[testing.TestKey.F9] = { keyCode: keyCodes__namespace.F9, key: 'F9' },
|
---|
804 | _a[testing.TestKey.F10] = { keyCode: keyCodes__namespace.F10, key: 'F10' },
|
---|
805 | _a[testing.TestKey.F11] = { keyCode: keyCodes__namespace.F11, key: 'F11' },
|
---|
806 | _a[testing.TestKey.F12] = { keyCode: keyCodes__namespace.F12, key: 'F12' },
|
---|
807 | _a[testing.TestKey.META] = { keyCode: keyCodes__namespace.META, key: 'Meta' },
|
---|
808 | _a);
|
---|
809 | /** A `TestElement` implementation for unit tests. */
|
---|
810 | var UnitTestElement = /** @class */ (function () {
|
---|
811 | function UnitTestElement(element, _stabilize) {
|
---|
812 | this.element = element;
|
---|
813 | this._stabilize = _stabilize;
|
---|
814 | }
|
---|
815 | /** Blur the element. */
|
---|
816 | UnitTestElement.prototype.blur = function () {
|
---|
817 | return __awaiter(this, void 0, void 0, function () {
|
---|
818 | return __generator(this, function (_a) {
|
---|
819 | switch (_a.label) {
|
---|
820 | case 0:
|
---|
821 | triggerBlur(this.element);
|
---|
822 | return [4 /*yield*/, this._stabilize()];
|
---|
823 | case 1:
|
---|
824 | _a.sent();
|
---|
825 | return [2 /*return*/];
|
---|
826 | }
|
---|
827 | });
|
---|
828 | });
|
---|
829 | };
|
---|
830 | /** Clear the element's input (for input and textarea elements only). */
|
---|
831 | UnitTestElement.prototype.clear = function () {
|
---|
832 | return __awaiter(this, void 0, void 0, function () {
|
---|
833 | return __generator(this, function (_a) {
|
---|
834 | switch (_a.label) {
|
---|
835 | case 0:
|
---|
836 | if (!isTextInput(this.element)) {
|
---|
837 | throw Error('Attempting to clear an invalid element');
|
---|
838 | }
|
---|
839 | clearElement(this.element);
|
---|
840 | return [4 /*yield*/, this._stabilize()];
|
---|
841 | case 1:
|
---|
842 | _a.sent();
|
---|
843 | return [2 /*return*/];
|
---|
844 | }
|
---|
845 | });
|
---|
846 | });
|
---|
847 | };
|
---|
848 | UnitTestElement.prototype.click = function () {
|
---|
849 | var args = [];
|
---|
850 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
851 | args[_i] = arguments[_i];
|
---|
852 | }
|
---|
853 | return __awaiter(this, void 0, void 0, function () {
|
---|
854 | return __generator(this, function (_a) {
|
---|
855 | switch (_a.label) {
|
---|
856 | case 0: return [4 /*yield*/, this._dispatchMouseEventSequence('click', args, 0)];
|
---|
857 | case 1:
|
---|
858 | _a.sent();
|
---|
859 | return [4 /*yield*/, this._stabilize()];
|
---|
860 | case 2:
|
---|
861 | _a.sent();
|
---|
862 | return [2 /*return*/];
|
---|
863 | }
|
---|
864 | });
|
---|
865 | });
|
---|
866 | };
|
---|
867 | UnitTestElement.prototype.rightClick = function () {
|
---|
868 | var args = [];
|
---|
869 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
870 | args[_i] = arguments[_i];
|
---|
871 | }
|
---|
872 | return __awaiter(this, void 0, void 0, function () {
|
---|
873 | return __generator(this, function (_a) {
|
---|
874 | switch (_a.label) {
|
---|
875 | case 0: return [4 /*yield*/, this._dispatchMouseEventSequence('contextmenu', args, 2)];
|
---|
876 | case 1:
|
---|
877 | _a.sent();
|
---|
878 | return [4 /*yield*/, this._stabilize()];
|
---|
879 | case 2:
|
---|
880 | _a.sent();
|
---|
881 | return [2 /*return*/];
|
---|
882 | }
|
---|
883 | });
|
---|
884 | });
|
---|
885 | };
|
---|
886 | /** Focus the element. */
|
---|
887 | UnitTestElement.prototype.focus = function () {
|
---|
888 | return __awaiter(this, void 0, void 0, function () {
|
---|
889 | return __generator(this, function (_a) {
|
---|
890 | switch (_a.label) {
|
---|
891 | case 0:
|
---|
892 | triggerFocus(this.element);
|
---|
893 | return [4 /*yield*/, this._stabilize()];
|
---|
894 | case 1:
|
---|
895 | _a.sent();
|
---|
896 | return [2 /*return*/];
|
---|
897 | }
|
---|
898 | });
|
---|
899 | });
|
---|
900 | };
|
---|
901 | /** Get the computed value of the given CSS property for the element. */
|
---|
902 | UnitTestElement.prototype.getCssValue = function (property) {
|
---|
903 | return __awaiter(this, void 0, void 0, function () {
|
---|
904 | return __generator(this, function (_a) {
|
---|
905 | switch (_a.label) {
|
---|
906 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
907 | case 1:
|
---|
908 | _a.sent();
|
---|
909 | // TODO(mmalerba): Consider adding value normalization if we run into common cases where its
|
---|
910 | // needed.
|
---|
911 | return [2 /*return*/, getComputedStyle(this.element).getPropertyValue(property)];
|
---|
912 | }
|
---|
913 | });
|
---|
914 | });
|
---|
915 | };
|
---|
916 | /** Hovers the mouse over the element. */
|
---|
917 | UnitTestElement.prototype.hover = function () {
|
---|
918 | return __awaiter(this, void 0, void 0, function () {
|
---|
919 | return __generator(this, function (_a) {
|
---|
920 | switch (_a.label) {
|
---|
921 | case 0:
|
---|
922 | this._dispatchPointerEventIfSupported('pointerenter');
|
---|
923 | dispatchMouseEvent(this.element, 'mouseenter');
|
---|
924 | return [4 /*yield*/, this._stabilize()];
|
---|
925 | case 1:
|
---|
926 | _a.sent();
|
---|
927 | return [2 /*return*/];
|
---|
928 | }
|
---|
929 | });
|
---|
930 | });
|
---|
931 | };
|
---|
932 | /** Moves the mouse away from the element. */
|
---|
933 | UnitTestElement.prototype.mouseAway = function () {
|
---|
934 | return __awaiter(this, void 0, void 0, function () {
|
---|
935 | return __generator(this, function (_a) {
|
---|
936 | switch (_a.label) {
|
---|
937 | case 0:
|
---|
938 | this._dispatchPointerEventIfSupported('pointerleave');
|
---|
939 | dispatchMouseEvent(this.element, 'mouseleave');
|
---|
940 | return [4 /*yield*/, this._stabilize()];
|
---|
941 | case 1:
|
---|
942 | _a.sent();
|
---|
943 | return [2 /*return*/];
|
---|
944 | }
|
---|
945 | });
|
---|
946 | });
|
---|
947 | };
|
---|
948 | UnitTestElement.prototype.sendKeys = function () {
|
---|
949 | var modifiersAndKeys = [];
|
---|
950 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
951 | modifiersAndKeys[_i] = arguments[_i];
|
---|
952 | }
|
---|
953 | return __awaiter(this, void 0, void 0, function () {
|
---|
954 | var args;
|
---|
955 | return __generator(this, function (_a) {
|
---|
956 | switch (_a.label) {
|
---|
957 | case 0:
|
---|
958 | args = modifiersAndKeys.map(function (k) { return typeof k === 'number' ? keyMap[k] : k; });
|
---|
959 | typeInElement.apply(void 0, __spreadArray([this.element], __read(args)));
|
---|
960 | return [4 /*yield*/, this._stabilize()];
|
---|
961 | case 1:
|
---|
962 | _a.sent();
|
---|
963 | return [2 /*return*/];
|
---|
964 | }
|
---|
965 | });
|
---|
966 | });
|
---|
967 | };
|
---|
968 | /**
|
---|
969 | * Gets the text from the element.
|
---|
970 | * @param options Options that affect what text is included.
|
---|
971 | */
|
---|
972 | UnitTestElement.prototype.text = function (options) {
|
---|
973 | return __awaiter(this, void 0, void 0, function () {
|
---|
974 | return __generator(this, function (_a) {
|
---|
975 | switch (_a.label) {
|
---|
976 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
977 | case 1:
|
---|
978 | _a.sent();
|
---|
979 | if (options === null || options === void 0 ? void 0 : options.exclude) {
|
---|
980 | return [2 /*return*/, testing._getTextWithExcludedElements(this.element, options.exclude)];
|
---|
981 | }
|
---|
982 | return [2 /*return*/, (this.element.textContent || '').trim()];
|
---|
983 | }
|
---|
984 | });
|
---|
985 | });
|
---|
986 | };
|
---|
987 | /** Gets the value for the given attribute from the element. */
|
---|
988 | UnitTestElement.prototype.getAttribute = function (name) {
|
---|
989 | return __awaiter(this, void 0, void 0, function () {
|
---|
990 | return __generator(this, function (_a) {
|
---|
991 | switch (_a.label) {
|
---|
992 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
993 | case 1:
|
---|
994 | _a.sent();
|
---|
995 | return [2 /*return*/, this.element.getAttribute(name)];
|
---|
996 | }
|
---|
997 | });
|
---|
998 | });
|
---|
999 | };
|
---|
1000 | /** Checks whether the element has the given class. */
|
---|
1001 | UnitTestElement.prototype.hasClass = function (name) {
|
---|
1002 | return __awaiter(this, void 0, void 0, function () {
|
---|
1003 | return __generator(this, function (_a) {
|
---|
1004 | switch (_a.label) {
|
---|
1005 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
1006 | case 1:
|
---|
1007 | _a.sent();
|
---|
1008 | return [2 /*return*/, this.element.classList.contains(name)];
|
---|
1009 | }
|
---|
1010 | });
|
---|
1011 | });
|
---|
1012 | };
|
---|
1013 | /** Gets the dimensions of the element. */
|
---|
1014 | UnitTestElement.prototype.getDimensions = function () {
|
---|
1015 | return __awaiter(this, void 0, void 0, function () {
|
---|
1016 | return __generator(this, function (_a) {
|
---|
1017 | switch (_a.label) {
|
---|
1018 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
1019 | case 1:
|
---|
1020 | _a.sent();
|
---|
1021 | return [2 /*return*/, this.element.getBoundingClientRect()];
|
---|
1022 | }
|
---|
1023 | });
|
---|
1024 | });
|
---|
1025 | };
|
---|
1026 | /** Gets the value of a property of an element. */
|
---|
1027 | UnitTestElement.prototype.getProperty = function (name) {
|
---|
1028 | return __awaiter(this, void 0, void 0, function () {
|
---|
1029 | return __generator(this, function (_a) {
|
---|
1030 | switch (_a.label) {
|
---|
1031 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
1032 | case 1:
|
---|
1033 | _a.sent();
|
---|
1034 | return [2 /*return*/, this.element[name]];
|
---|
1035 | }
|
---|
1036 | });
|
---|
1037 | });
|
---|
1038 | };
|
---|
1039 | /** Sets the value of a property of an input. */
|
---|
1040 | UnitTestElement.prototype.setInputValue = function (value) {
|
---|
1041 | return __awaiter(this, void 0, void 0, function () {
|
---|
1042 | return __generator(this, function (_a) {
|
---|
1043 | switch (_a.label) {
|
---|
1044 | case 0:
|
---|
1045 | this.element.value = value;
|
---|
1046 | return [4 /*yield*/, this._stabilize()];
|
---|
1047 | case 1:
|
---|
1048 | _a.sent();
|
---|
1049 | return [2 /*return*/];
|
---|
1050 | }
|
---|
1051 | });
|
---|
1052 | });
|
---|
1053 | };
|
---|
1054 | /** Selects the options at the specified indexes inside of a native `select` element. */
|
---|
1055 | UnitTestElement.prototype.selectOptions = function () {
|
---|
1056 | var optionIndexes = [];
|
---|
1057 | for (var _i = 0; _i < arguments.length; _i++) {
|
---|
1058 | optionIndexes[_i] = arguments[_i];
|
---|
1059 | }
|
---|
1060 | return __awaiter(this, void 0, void 0, function () {
|
---|
1061 | var hasChanged, options, indexes, i, option, wasSelected;
|
---|
1062 | return __generator(this, function (_a) {
|
---|
1063 | switch (_a.label) {
|
---|
1064 | case 0:
|
---|
1065 | hasChanged = false;
|
---|
1066 | options = this.element.querySelectorAll('option');
|
---|
1067 | indexes = new Set(optionIndexes);
|
---|
1068 | for (i = 0; i < options.length; i++) {
|
---|
1069 | option = options[i];
|
---|
1070 | wasSelected = option.selected;
|
---|
1071 | // We have to go through `option.selected`, because `HTMLSelectElement.value` doesn't
|
---|
1072 | // allow for multiple options to be selected, even in `multiple` mode.
|
---|
1073 | option.selected = indexes.has(i);
|
---|
1074 | if (option.selected !== wasSelected) {
|
---|
1075 | hasChanged = true;
|
---|
1076 | dispatchFakeEvent(this.element, 'change');
|
---|
1077 | }
|
---|
1078 | }
|
---|
1079 | if (!hasChanged) return [3 /*break*/, 2];
|
---|
1080 | return [4 /*yield*/, this._stabilize()];
|
---|
1081 | case 1:
|
---|
1082 | _a.sent();
|
---|
1083 | _a.label = 2;
|
---|
1084 | case 2: return [2 /*return*/];
|
---|
1085 | }
|
---|
1086 | });
|
---|
1087 | });
|
---|
1088 | };
|
---|
1089 | /** Checks whether this element matches the given selector. */
|
---|
1090 | UnitTestElement.prototype.matchesSelector = function (selector) {
|
---|
1091 | return __awaiter(this, void 0, void 0, function () {
|
---|
1092 | var elementPrototype;
|
---|
1093 | return __generator(this, function (_a) {
|
---|
1094 | switch (_a.label) {
|
---|
1095 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
1096 | case 1:
|
---|
1097 | _a.sent();
|
---|
1098 | elementPrototype = Element.prototype;
|
---|
1099 | return [2 /*return*/, (elementPrototype['matches'] || elementPrototype['msMatchesSelector'])
|
---|
1100 | .call(this.element, selector)];
|
---|
1101 | }
|
---|
1102 | });
|
---|
1103 | });
|
---|
1104 | };
|
---|
1105 | /** Checks whether the element is focused. */
|
---|
1106 | UnitTestElement.prototype.isFocused = function () {
|
---|
1107 | return __awaiter(this, void 0, void 0, function () {
|
---|
1108 | return __generator(this, function (_a) {
|
---|
1109 | switch (_a.label) {
|
---|
1110 | case 0: return [4 /*yield*/, this._stabilize()];
|
---|
1111 | case 1:
|
---|
1112 | _a.sent();
|
---|
1113 | return [2 /*return*/, document.activeElement === this.element];
|
---|
1114 | }
|
---|
1115 | });
|
---|
1116 | });
|
---|
1117 | };
|
---|
1118 | /**
|
---|
1119 | * Dispatches an event with a particular name.
|
---|
1120 | * @param name Name of the event to be dispatched.
|
---|
1121 | */
|
---|
1122 | UnitTestElement.prototype.dispatchEvent = function (name, data) {
|
---|
1123 | return __awaiter(this, void 0, void 0, function () {
|
---|
1124 | var event;
|
---|
1125 | return __generator(this, function (_a) {
|
---|
1126 | switch (_a.label) {
|
---|
1127 | case 0:
|
---|
1128 | event = createFakeEvent(name);
|
---|
1129 | if (data) {
|
---|
1130 | // tslint:disable-next-line:ban Have to use `Object.assign` to preserve the original object.
|
---|
1131 | Object.assign(event, data);
|
---|
1132 | }
|
---|
1133 | dispatchEvent(this.element, event);
|
---|
1134 | return [4 /*yield*/, this._stabilize()];
|
---|
1135 | case 1:
|
---|
1136 | _a.sent();
|
---|
1137 | return [2 /*return*/];
|
---|
1138 | }
|
---|
1139 | });
|
---|
1140 | });
|
---|
1141 | };
|
---|
1142 | /**
|
---|
1143 | * Dispatches a pointer event on the current element if the browser supports it.
|
---|
1144 | * @param name Name of the pointer event to be dispatched.
|
---|
1145 | * @param clientX Coordinate of the user's pointer along the X axis.
|
---|
1146 | * @param clientY Coordinate of the user's pointer along the Y axis.
|
---|
1147 | * @param button Mouse button that should be pressed when dispatching the event.
|
---|
1148 | */
|
---|
1149 | UnitTestElement.prototype._dispatchPointerEventIfSupported = function (name, clientX, clientY, button) {
|
---|
1150 | // The latest versions of all browsers we support have the new `PointerEvent` API.
|
---|
1151 | // Though since we capture the two most recent versions of these browsers, we also
|
---|
1152 | // need to support Safari 12 at time of writing. Safari 12 does not have support for this,
|
---|
1153 | // so we need to conditionally create and dispatch these events based on feature detection.
|
---|
1154 | if (typeof PointerEvent !== 'undefined' && PointerEvent) {
|
---|
1155 | dispatchPointerEvent(this.element, name, clientX, clientY, { isPrimary: true, button: button });
|
---|
1156 | }
|
---|
1157 | };
|
---|
1158 | /** Dispatches all the events that are part of a mouse event sequence. */
|
---|
1159 | UnitTestElement.prototype._dispatchMouseEventSequence = function (name, args, button) {
|
---|
1160 | return __awaiter(this, void 0, void 0, function () {
|
---|
1161 | var clientX, clientY, modifiers, _a, left, top, width, height, relativeX, relativeY;
|
---|
1162 | return __generator(this, function (_b) {
|
---|
1163 | switch (_b.label) {
|
---|
1164 | case 0:
|
---|
1165 | clientX = undefined;
|
---|
1166 | clientY = undefined;
|
---|
1167 | modifiers = {};
|
---|
1168 | if (args.length && typeof args[args.length - 1] === 'object') {
|
---|
1169 | modifiers = args.pop();
|
---|
1170 | }
|
---|
1171 | if (!args.length) return [3 /*break*/, 2];
|
---|
1172 | return [4 /*yield*/, this.getDimensions()];
|
---|
1173 | case 1:
|
---|
1174 | _a = _b.sent(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
|
---|
1175 | relativeX = args[0] === 'center' ? width / 2 : args[0];
|
---|
1176 | relativeY = args[0] === 'center' ? height / 2 : args[1];
|
---|
1177 | // Round the computed click position as decimal pixels are not
|
---|
1178 | // supported by mouse events and could lead to unexpected results.
|
---|
1179 | clientX = Math.round(left + relativeX);
|
---|
1180 | clientY = Math.round(top + relativeY);
|
---|
1181 | _b.label = 2;
|
---|
1182 | case 2:
|
---|
1183 | this._dispatchPointerEventIfSupported('pointerdown', clientX, clientY, button);
|
---|
1184 | dispatchMouseEvent(this.element, 'mousedown', clientX, clientY, button, modifiers);
|
---|
1185 | this._dispatchPointerEventIfSupported('pointerup', clientX, clientY, button);
|
---|
1186 | dispatchMouseEvent(this.element, 'mouseup', clientX, clientY, button, modifiers);
|
---|
1187 | dispatchMouseEvent(this.element, name, clientX, clientY, button, modifiers);
|
---|
1188 | // This call to _stabilize should not be needed since the callers will already do that them-
|
---|
1189 | // selves. Nevertheless it breaks some tests in g3 without it. It needs to be investigated
|
---|
1190 | // why removing breaks those tests.
|
---|
1191 | return [4 /*yield*/, this._stabilize()];
|
---|
1192 | case 3:
|
---|
1193 | // This call to _stabilize should not be needed since the callers will already do that them-
|
---|
1194 | // selves. Nevertheless it breaks some tests in g3 without it. It needs to be investigated
|
---|
1195 | // why removing breaks those tests.
|
---|
1196 | _b.sent();
|
---|
1197 | return [2 /*return*/];
|
---|
1198 | }
|
---|
1199 | });
|
---|
1200 | });
|
---|
1201 | };
|
---|
1202 | return UnitTestElement;
|
---|
1203 | }());
|
---|
1204 |
|
---|
1205 | /** The default environment options. */
|
---|
1206 | var defaultEnvironmentOptions = {
|
---|
1207 | queryFn: function (selector, root) { return root.querySelectorAll(selector); }
|
---|
1208 | };
|
---|
1209 | /** Whether auto change detection is currently disabled. */
|
---|
1210 | var disableAutoChangeDetection = false;
|
---|
1211 | /**
|
---|
1212 | * The set of non-destroyed fixtures currently being used by `TestbedHarnessEnvironment` instances.
|
---|
1213 | */
|
---|
1214 | var activeFixtures = new Set();
|
---|
1215 | /**
|
---|
1216 | * Installs a handler for change detection batching status changes for a specific fixture.
|
---|
1217 | * @param fixture The fixture to handle change detection batching for.
|
---|
1218 | */
|
---|
1219 | function installAutoChangeDetectionStatusHandler(fixture) {
|
---|
1220 | if (!activeFixtures.size) {
|
---|
1221 | testing.handleAutoChangeDetectionStatus(function (_a) {
|
---|
1222 | var isDisabled = _a.isDisabled, onDetectChangesNow = _a.onDetectChangesNow;
|
---|
1223 | disableAutoChangeDetection = isDisabled;
|
---|
1224 | if (onDetectChangesNow) {
|
---|
1225 | Promise.all(Array.from(activeFixtures).map(detectChanges)).then(onDetectChangesNow);
|
---|
1226 | }
|
---|
1227 | });
|
---|
1228 | }
|
---|
1229 | activeFixtures.add(fixture);
|
---|
1230 | }
|
---|
1231 | /**
|
---|
1232 | * Uninstalls a handler for change detection batching status changes for a specific fixture.
|
---|
1233 | * @param fixture The fixture to stop handling change detection batching for.
|
---|
1234 | */
|
---|
1235 | function uninstallAutoChangeDetectionStatusHandler(fixture) {
|
---|
1236 | activeFixtures.delete(fixture);
|
---|
1237 | if (!activeFixtures.size) {
|
---|
1238 | testing.stopHandlingAutoChangeDetectionStatus();
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 | /** Whether we are currently in the fake async zone. */
|
---|
1242 | function isInFakeAsyncZone() {
|
---|
1243 | return Zone.current.get('FakeAsyncTestZoneSpec') != null;
|
---|
1244 | }
|
---|
1245 | /**
|
---|
1246 | * Triggers change detection for a specific fixture.
|
---|
1247 | * @param fixture The fixture to trigger change detection for.
|
---|
1248 | */
|
---|
1249 | function detectChanges(fixture) {
|
---|
1250 | return __awaiter(this, void 0, void 0, function () {
|
---|
1251 | return __generator(this, function (_a) {
|
---|
1252 | switch (_a.label) {
|
---|
1253 | case 0:
|
---|
1254 | fixture.detectChanges();
|
---|
1255 | if (!isInFakeAsyncZone()) return [3 /*break*/, 1];
|
---|
1256 | testing$1.flush();
|
---|
1257 | return [3 /*break*/, 3];
|
---|
1258 | case 1: return [4 /*yield*/, fixture.whenStable()];
|
---|
1259 | case 2:
|
---|
1260 | _a.sent();
|
---|
1261 | _a.label = 3;
|
---|
1262 | case 3: return [2 /*return*/];
|
---|
1263 | }
|
---|
1264 | });
|
---|
1265 | });
|
---|
1266 | }
|
---|
1267 | /** A `HarnessEnvironment` implementation for Angular's Testbed. */
|
---|
1268 | var TestbedHarnessEnvironment = /** @class */ (function (_super) {
|
---|
1269 | __extends(TestbedHarnessEnvironment, _super);
|
---|
1270 | function TestbedHarnessEnvironment(rawRootElement, _fixture, options) {
|
---|
1271 | var _this = _super.call(this, rawRootElement) || this;
|
---|
1272 | _this._fixture = _fixture;
|
---|
1273 | /** Whether the environment has been destroyed. */
|
---|
1274 | _this._destroyed = false;
|
---|
1275 | _this._options = Object.assign(Object.assign({}, defaultEnvironmentOptions), options);
|
---|
1276 | _this._taskState = TaskStateZoneInterceptor.setup();
|
---|
1277 | installAutoChangeDetectionStatusHandler(_fixture);
|
---|
1278 | _fixture.componentRef.onDestroy(function () {
|
---|
1279 | uninstallAutoChangeDetectionStatusHandler(_fixture);
|
---|
1280 | _this._destroyed = true;
|
---|
1281 | });
|
---|
1282 | return _this;
|
---|
1283 | }
|
---|
1284 | /** Creates a `HarnessLoader` rooted at the given fixture's root element. */
|
---|
1285 | TestbedHarnessEnvironment.loader = function (fixture, options) {
|
---|
1286 | return new TestbedHarnessEnvironment(fixture.nativeElement, fixture, options);
|
---|
1287 | };
|
---|
1288 | /**
|
---|
1289 | * Creates a `HarnessLoader` at the document root. This can be used if harnesses are
|
---|
1290 | * located outside of a fixture (e.g. overlays appended to the document body).
|
---|
1291 | */
|
---|
1292 | TestbedHarnessEnvironment.documentRootLoader = function (fixture, options) {
|
---|
1293 | return new TestbedHarnessEnvironment(document.body, fixture, options);
|
---|
1294 | };
|
---|
1295 | /** Gets the native DOM element corresponding to the given TestElement. */
|
---|
1296 | TestbedHarnessEnvironment.getNativeElement = function (el) {
|
---|
1297 | if (el instanceof UnitTestElement) {
|
---|
1298 | return el.element;
|
---|
1299 | }
|
---|
1300 | throw Error('This TestElement was not created by the TestbedHarnessEnvironment');
|
---|
1301 | };
|
---|
1302 | /**
|
---|
1303 | * Creates an instance of the given harness type, using the fixture's root element as the
|
---|
1304 | * harness's host element. This method should be used when creating a harness for the root element
|
---|
1305 | * of a fixture, as components do not have the correct selector when they are created as the root
|
---|
1306 | * of the fixture.
|
---|
1307 | */
|
---|
1308 | TestbedHarnessEnvironment.harnessForFixture = function (fixture, harnessType, options) {
|
---|
1309 | return __awaiter(this, void 0, void 0, function () {
|
---|
1310 | var environment;
|
---|
1311 | return __generator(this, function (_a) {
|
---|
1312 | switch (_a.label) {
|
---|
1313 | case 0:
|
---|
1314 | environment = new TestbedHarnessEnvironment(fixture.nativeElement, fixture, options);
|
---|
1315 | return [4 /*yield*/, environment.forceStabilize()];
|
---|
1316 | case 1:
|
---|
1317 | _a.sent();
|
---|
1318 | return [2 /*return*/, environment.createComponentHarness(harnessType, fixture.nativeElement)];
|
---|
1319 | }
|
---|
1320 | });
|
---|
1321 | });
|
---|
1322 | };
|
---|
1323 | /**
|
---|
1324 | * Flushes change detection and async tasks captured in the Angular zone.
|
---|
1325 | * In most cases it should not be necessary to call this manually. However, there may be some edge
|
---|
1326 | * cases where it is needed to fully flush animation events.
|
---|
1327 | */
|
---|
1328 | TestbedHarnessEnvironment.prototype.forceStabilize = function () {
|
---|
1329 | return __awaiter(this, void 0, void 0, function () {
|
---|
1330 | return __generator(this, function (_a) {
|
---|
1331 | switch (_a.label) {
|
---|
1332 | case 0:
|
---|
1333 | if (!!disableAutoChangeDetection) return [3 /*break*/, 2];
|
---|
1334 | if (this._destroyed) {
|
---|
1335 | throw Error('Harness is attempting to use a fixture that has already been destroyed.');
|
---|
1336 | }
|
---|
1337 | return [4 /*yield*/, detectChanges(this._fixture)];
|
---|
1338 | case 1:
|
---|
1339 | _a.sent();
|
---|
1340 | _a.label = 2;
|
---|
1341 | case 2: return [2 /*return*/];
|
---|
1342 | }
|
---|
1343 | });
|
---|
1344 | });
|
---|
1345 | };
|
---|
1346 | /**
|
---|
1347 | * Waits for all scheduled or running async tasks to complete. This allows harness
|
---|
1348 | * authors to wait for async tasks outside of the Angular zone.
|
---|
1349 | */
|
---|
1350 | TestbedHarnessEnvironment.prototype.waitForTasksOutsideAngular = function () {
|
---|
1351 | return __awaiter(this, void 0, void 0, function () {
|
---|
1352 | return __generator(this, function (_a) {
|
---|
1353 | switch (_a.label) {
|
---|
1354 | case 0:
|
---|
1355 | // If we run in the fake async zone, we run "flush" to run any scheduled tasks. This
|
---|
1356 | // ensures that the harnesses behave inside of the FakeAsyncTestZone similar to the
|
---|
1357 | // "AsyncTestZone" and the root zone (i.e. neither fakeAsync or async). Note that we
|
---|
1358 | // cannot just rely on the task state observable to become stable because the state will
|
---|
1359 | // never change. This is because the task queue will be only drained if the fake async
|
---|
1360 | // zone is being flushed.
|
---|
1361 | if (isInFakeAsyncZone()) {
|
---|
1362 | testing$1.flush();
|
---|
1363 | }
|
---|
1364 | // Wait until the task queue has been drained and the zone is stable. Note that
|
---|
1365 | // we cannot rely on "fixture.whenStable" since it does not catch tasks scheduled
|
---|
1366 | // outside of the Angular zone. For test harnesses, we want to ensure that the
|
---|
1367 | // app is fully stabilized and therefore need to use our own zone interceptor.
|
---|
1368 | return [4 /*yield*/, this._taskState.pipe(operators.takeWhile(function (state) { return !state.stable; })).toPromise()];
|
---|
1369 | case 1:
|
---|
1370 | // Wait until the task queue has been drained and the zone is stable. Note that
|
---|
1371 | // we cannot rely on "fixture.whenStable" since it does not catch tasks scheduled
|
---|
1372 | // outside of the Angular zone. For test harnesses, we want to ensure that the
|
---|
1373 | // app is fully stabilized and therefore need to use our own zone interceptor.
|
---|
1374 | _a.sent();
|
---|
1375 | return [2 /*return*/];
|
---|
1376 | }
|
---|
1377 | });
|
---|
1378 | });
|
---|
1379 | };
|
---|
1380 | /** Gets the root element for the document. */
|
---|
1381 | TestbedHarnessEnvironment.prototype.getDocumentRoot = function () {
|
---|
1382 | return document.body;
|
---|
1383 | };
|
---|
1384 | /** Creates a `TestElement` from a raw element. */
|
---|
1385 | TestbedHarnessEnvironment.prototype.createTestElement = function (element) {
|
---|
1386 | var _this = this;
|
---|
1387 | return new UnitTestElement(element, function () { return _this.forceStabilize(); });
|
---|
1388 | };
|
---|
1389 | /** Creates a `HarnessLoader` rooted at the given raw element. */
|
---|
1390 | TestbedHarnessEnvironment.prototype.createEnvironment = function (element) {
|
---|
1391 | return new TestbedHarnessEnvironment(element, this._fixture, this._options);
|
---|
1392 | };
|
---|
1393 | /**
|
---|
1394 | * Gets a list of all elements matching the given selector under this environment's root element.
|
---|
1395 | */
|
---|
1396 | TestbedHarnessEnvironment.prototype.getAllRawElements = function (selector) {
|
---|
1397 | return __awaiter(this, void 0, void 0, function () {
|
---|
1398 | return __generator(this, function (_a) {
|
---|
1399 | switch (_a.label) {
|
---|
1400 | case 0: return [4 /*yield*/, this.forceStabilize()];
|
---|
1401 | case 1:
|
---|
1402 | _a.sent();
|
---|
1403 | return [2 /*return*/, Array.from(this._options.queryFn(selector, this.rawRootElement))];
|
---|
1404 | }
|
---|
1405 | });
|
---|
1406 | });
|
---|
1407 | };
|
---|
1408 | return TestbedHarnessEnvironment;
|
---|
1409 | }(testing.HarnessEnvironment));
|
---|
1410 |
|
---|
1411 | /**
|
---|
1412 | * @license
|
---|
1413 | * Copyright Google LLC All Rights Reserved.
|
---|
1414 | *
|
---|
1415 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1416 | * found in the LICENSE file at https://angular.io/license
|
---|
1417 | */
|
---|
1418 |
|
---|
1419 | /**
|
---|
1420 | * @license
|
---|
1421 | * Copyright Google LLC All Rights Reserved.
|
---|
1422 | *
|
---|
1423 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1424 | * found in the LICENSE file at https://angular.io/license
|
---|
1425 | */
|
---|
1426 |
|
---|
1427 | exports.TestbedHarnessEnvironment = TestbedHarnessEnvironment;
|
---|
1428 | exports.UnitTestElement = UnitTestElement;
|
---|
1429 |
|
---|
1430 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
1431 |
|
---|
1432 | })));
|
---|
1433 | //# sourceMappingURL=cdk-testing-testbed.umd.js.map
|
---|