source: trip-planner-front/node_modules/@angular/compiler/fesm2015/testing.js@ 76712b2

Last change on this file since 76712b2 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 9.4 KB
RevLine 
[6a3a178]1/**
[e29cc2e]2 * @license Angular v12.2.13
[6a3a178]3 * (c) 2010-2021 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { ResourceLoader, core, DirectiveResolver, NgModuleResolver, PipeResolver } from '@angular/compiler';
8
9/**
10 * @license
11 * Copyright Google LLC All Rights Reserved.
12 *
13 * Use of this source code is governed by an MIT-style license that can be
14 * found in the LICENSE file at https://angular.io/license
15 */
16/**
17 * A mock implementation of {@link ResourceLoader} that allows outgoing requests to be mocked
18 * and responded to within a single test, without going to the network.
19 */
20class MockResourceLoader extends ResourceLoader {
21 constructor() {
22 super(...arguments);
23 this._expectations = [];
24 this._definitions = new Map();
25 this._requests = [];
26 }
27 get(url) {
28 const request = new _PendingRequest(url);
29 this._requests.push(request);
30 return request.getPromise();
31 }
32 hasPendingRequests() {
33 return !!this._requests.length;
34 }
35 /**
36 * Add an expectation for the given URL. Incoming requests will be checked against
37 * the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
38 * can be used to check if any expectations have not yet been met.
39 *
40 * The response given will be returned if the expectation matches.
41 */
42 expect(url, response) {
43 const expectation = new _Expectation(url, response);
44 this._expectations.push(expectation);
45 }
46 /**
47 * Add a definition for the given URL to return the given response. Unlike expectations,
48 * definitions have no order and will satisfy any matching request at any time. Also
49 * unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
50 * to return an error.
51 */
52 when(url, response) {
53 this._definitions.set(url, response);
54 }
55 /**
56 * Process pending requests and verify there are no outstanding expectations. Also fails
57 * if no requests are pending.
58 */
59 flush() {
60 if (this._requests.length === 0) {
61 throw new Error('No pending requests to flush');
62 }
63 do {
64 this._processRequest(this._requests.shift());
65 } while (this._requests.length > 0);
66 this.verifyNoOutstandingExpectations();
67 }
68 /**
69 * Throw an exception if any expectations have not been satisfied.
70 */
71 verifyNoOutstandingExpectations() {
72 if (this._expectations.length === 0)
73 return;
74 const urls = [];
75 for (let i = 0; i < this._expectations.length; i++) {
76 const expectation = this._expectations[i];
77 urls.push(expectation.url);
78 }
79 throw new Error(`Unsatisfied requests: ${urls.join(', ')}`);
80 }
81 _processRequest(request) {
82 const url = request.url;
83 if (this._expectations.length > 0) {
84 const expectation = this._expectations[0];
85 if (expectation.url == url) {
86 remove(this._expectations, expectation);
87 request.complete(expectation.response);
88 return;
89 }
90 }
91 if (this._definitions.has(url)) {
92 const response = this._definitions.get(url);
93 request.complete(response == null ? null : response);
94 return;
95 }
96 throw new Error(`Unexpected request ${url}`);
97 }
98}
99class _PendingRequest {
100 constructor(url) {
101 this.url = url;
102 this.promise = new Promise((res, rej) => {
103 this.resolve = res;
104 this.reject = rej;
105 });
106 }
107 complete(response) {
108 if (response == null) {
109 this.reject(`Failed to load ${this.url}`);
110 }
111 else {
112 this.resolve(response);
113 }
114 }
115 getPromise() {
116 return this.promise;
117 }
118}
119class _Expectation {
120 constructor(url, response) {
121 this.url = url;
122 this.response = response;
123 }
124}
125function remove(list, el) {
126 const index = list.indexOf(el);
127 if (index > -1) {
128 list.splice(index, 1);
129 }
130}
131
132/**
133 * @license
134 * Copyright Google LLC All Rights Reserved.
135 *
136 * Use of this source code is governed by an MIT-style license that can be
137 * found in the LICENSE file at https://angular.io/license
138 */
139class MockSchemaRegistry {
140 constructor(existingProperties, attrPropMapping, existingElements, invalidProperties, invalidAttributes) {
141 this.existingProperties = existingProperties;
142 this.attrPropMapping = attrPropMapping;
143 this.existingElements = existingElements;
144 this.invalidProperties = invalidProperties;
145 this.invalidAttributes = invalidAttributes;
146 }
147 hasProperty(tagName, property, schemas) {
148 const value = this.existingProperties[property];
149 return value === void 0 ? true : value;
150 }
151 hasElement(tagName, schemaMetas) {
152 const value = this.existingElements[tagName.toLowerCase()];
153 return value === void 0 ? true : value;
154 }
155 allKnownElementNames() {
156 return Object.keys(this.existingElements);
157 }
158 securityContext(selector, property, isAttribute) {
159 return core.SecurityContext.NONE;
160 }
161 getMappedPropName(attrName) {
162 return this.attrPropMapping[attrName] || attrName;
163 }
164 getDefaultComponentElementName() {
165 return 'ng-component';
166 }
167 validateProperty(name) {
168 if (this.invalidProperties.indexOf(name) > -1) {
169 return { error: true, msg: `Binding to property '${name}' is disallowed for security reasons` };
170 }
171 else {
172 return { error: false };
173 }
174 }
175 validateAttribute(name) {
176 if (this.invalidAttributes.indexOf(name) > -1) {
177 return {
178 error: true,
179 msg: `Binding to attribute '${name}' is disallowed for security reasons`
180 };
181 }
182 else {
183 return { error: false };
184 }
185 }
186 normalizeAnimationStyleProperty(propName) {
187 return propName;
188 }
189 normalizeAnimationStyleValue(camelCaseProp, userProvidedProp, val) {
190 return { error: null, value: val.toString() };
191 }
192}
193
194/**
195 * @license
196 * Copyright Google LLC All Rights Reserved.
197 *
198 * Use of this source code is governed by an MIT-style license that can be
199 * found in the LICENSE file at https://angular.io/license
200 */
201/**
202 * An implementation of {@link DirectiveResolver} that allows overriding
203 * various properties of directives.
204 */
205class MockDirectiveResolver extends DirectiveResolver {
206 constructor(reflector) {
207 super(reflector);
208 this._directives = new Map();
209 }
210 resolve(type, throwIfNotFound = true) {
211 return this._directives.get(type) || super.resolve(type, throwIfNotFound);
212 }
213 /**
214 * Overrides the {@link core.Directive} for a directive.
215 */
216 setDirective(type, metadata) {
217 this._directives.set(type, metadata);
218 }
219}
220
221/**
222 * @license
223 * Copyright Google LLC All Rights Reserved.
224 *
225 * Use of this source code is governed by an MIT-style license that can be
226 * found in the LICENSE file at https://angular.io/license
227 */
228class MockNgModuleResolver extends NgModuleResolver {
229 constructor(reflector) {
230 super(reflector);
231 this._ngModules = new Map();
232 }
233 /**
234 * Overrides the {@link NgModule} for a module.
235 */
236 setNgModule(type, metadata) {
237 this._ngModules.set(type, metadata);
238 }
239 /**
240 * Returns the {@link NgModule} for a module:
241 * - Set the {@link NgModule} to the overridden view when it exists or fallback to the
242 * default
243 * `NgModuleResolver`, see `setNgModule`.
244 */
245 resolve(type, throwIfNotFound = true) {
246 return this._ngModules.get(type) || super.resolve(type, throwIfNotFound);
247 }
248}
249
250/**
251 * @license
252 * Copyright Google LLC All Rights Reserved.
253 *
254 * Use of this source code is governed by an MIT-style license that can be
255 * found in the LICENSE file at https://angular.io/license
256 */
257class MockPipeResolver extends PipeResolver {
258 constructor(refector) {
259 super(refector);
260 this._pipes = new Map();
261 }
262 /**
263 * Overrides the {@link Pipe} for a pipe.
264 */
265 setPipe(type, metadata) {
266 this._pipes.set(type, metadata);
267 }
268 /**
269 * Returns the {@link Pipe} for a pipe:
270 * - Set the {@link Pipe} to the overridden view when it exists or fallback to the
271 * default
272 * `PipeResolver`, see `setPipe`.
273 */
274 resolve(type, throwIfNotFound = true) {
275 let metadata = this._pipes.get(type);
276 if (!metadata) {
277 metadata = super.resolve(type, throwIfNotFound);
278 }
279 return metadata;
280 }
281}
282
283/**
284 * @license
285 * Copyright Google LLC All Rights Reserved.
286 *
287 * Use of this source code is governed by an MIT-style license that can be
288 * found in the LICENSE file at https://angular.io/license
289 */
290
291/**
292 * @license
293 * Copyright Google LLC All Rights Reserved.
294 *
295 * Use of this source code is governed by an MIT-style license that can be
296 * found in the LICENSE file at https://angular.io/license
297 */
298// This file only reexports content of the `src` folder. Keep it that way.
299
300/**
301 * @license
302 * Copyright Google LLC All Rights Reserved.
303 *
304 * Use of this source code is governed by an MIT-style license that can be
305 * found in the LICENSE file at https://angular.io/license
306 */
307
308/**
309 * Generated bundle index. Do not edit.
310 */
311
312export { MockDirectiveResolver, MockNgModuleResolver, MockPipeResolver, MockResourceLoader, MockSchemaRegistry };
313//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.