UNPKG

37.1 kBTypeScriptView Raw
1/** An async function that returns a promise when called. */
2export declare type AsyncFactoryFn<T> = () => Promise<T>;
3
4/** An async function that takes an item and an option value and returns a boolean promise. */
5export declare type AsyncOptionPredicate<T, O> = (item: T, option: O) => Promise<boolean>;
6
7/** An async function that takes an item and returns a boolean promise */
8export declare type AsyncPredicate<T> = (item: T) => Promise<boolean>;
9
10
11/** Represents the status of auto change detection. */
12export declare interface AutoChangeDetectionStatus {
13 /** Whether auto change detection is disabled. */
14 isDisabled: boolean;
15 /**
16 * An optional callback, if present it indicates that change detection should be run immediately,
17 * while handling the status change. The callback should then be called as soon as change
18 * detection is done.
19 */
20 onDetectChangesNow?: () => void;
21}
22
23/** A set of criteria that can be used to filter a list of `ComponentHarness` instances. */
24export declare interface BaseHarnessFilters {
25 /** Only find instances whose host element matches the given selector. */
26 selector?: string;
27 /** Only find instances that are nested under an element with the given selector. */
28 ancestor?: string;
29}
30
31/**
32 * Base class for component harnesses that all component harness authors should extend. This base
33 * component harness provides the basic ability to locate element and sub-component harness. It
34 * should be inherited when defining user's own harness.
35 */
36export declare abstract class ComponentHarness {
37 protected readonly locatorFactory: LocatorFactory;
38 constructor(locatorFactory: LocatorFactory);
39 /** Gets a `Promise` for the `TestElement` representing the host element of the component. */
40 host(): Promise<TestElement>;
41 /**
42 * Gets a `LocatorFactory` for the document root element. This factory can be used to create
43 * locators for elements that a component creates outside of its own root element. (e.g. by
44 * appending to document.body).
45 */
46 protected documentRootLocatorFactory(): LocatorFactory;
47 /**
48 * Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
49 * or element under the host element of this `ComponentHarness`.
50 * @param queries A list of queries specifying which harnesses and elements to search for:
51 * - A `string` searches for elements matching the CSS selector specified by the string.
52 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
53 * given class.
54 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
55 * predicate.
56 * @return An asynchronous locator function that searches for and returns a `Promise` for the
57 * first element or harness matching the given search criteria. Matches are ordered first by
58 * order in the DOM, and second by order in the queries list. If no matches are found, the
59 * `Promise` rejects. The type that the `Promise` resolves to is a union of all result types for
60 * each query.
61 *
62 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
63 * `DivHarness.hostSelector === 'div'`:
64 * - `await ch.locatorFor(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
65 * - `await ch.locatorFor('div', DivHarness)()` gets a `TestElement` instance for `#d1`
66 * - `await ch.locatorFor('span')()` throws because the `Promise` rejects.
67 */
68 protected locatorFor<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>>;
69 /**
70 * Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
71 * or element under the host element of this `ComponentHarness`.
72 * @param queries A list of queries specifying which harnesses and elements to search for:
73 * - A `string` searches for elements matching the CSS selector specified by the string.
74 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
75 * given class.
76 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
77 * predicate.
78 * @return An asynchronous locator function that searches for and returns a `Promise` for the
79 * first element or harness matching the given search criteria. Matches are ordered first by
80 * order in the DOM, and second by order in the queries list. If no matches are found, the
81 * `Promise` is resolved with `null`. The type that the `Promise` resolves to is a union of all
82 * result types for each query or null.
83 *
84 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
85 * `DivHarness.hostSelector === 'div'`:
86 * - `await ch.locatorForOptional(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
87 * - `await ch.locatorForOptional('div', DivHarness)()` gets a `TestElement` instance for `#d1`
88 * - `await ch.locatorForOptional('span')()` gets `null`.
89 */
90 protected locatorForOptional<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T> | null>;
91 /**
92 * Creates an asynchronous locator function that can be used to find `ComponentHarness` instances
93 * or elements under the host element of this `ComponentHarness`.
94 * @param queries A list of queries specifying which harnesses and elements to search for:
95 * - A `string` searches for elements matching the CSS selector specified by the string.
96 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
97 * given class.
98 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
99 * predicate.
100 * @return An asynchronous locator function that searches for and returns a `Promise` for all
101 * elements and harnesses matching the given search criteria. Matches are ordered first by
102 * order in the DOM, and second by order in the queries list. If an element matches more than
103 * one `ComponentHarness` class, the locator gets an instance of each for the same element. If
104 * an element matches multiple `string` selectors, only one `TestElement` instance is returned
105 * for that element. The type that the `Promise` resolves to is an array where each element is
106 * the union of all result types for each query.
107 *
108 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
109 * `DivHarness.hostSelector === 'div'` and `IdIsD1Harness.hostSelector === '#d1'`:
110 * - `await ch.locatorForAll(DivHarness, 'div')()` gets `[
111 * DivHarness, // for #d1
112 * TestElement, // for #d1
113 * DivHarness, // for #d2
114 * TestElement // for #d2
115 * ]`
116 * - `await ch.locatorForAll('div', '#d1')()` gets `[
117 * TestElement, // for #d1
118 * TestElement // for #d2
119 * ]`
120 * - `await ch.locatorForAll(DivHarness, IdIsD1Harness)()` gets `[
121 * DivHarness, // for #d1
122 * IdIsD1Harness, // for #d1
123 * DivHarness // for #d2
124 * ]`
125 * - `await ch.locatorForAll('span')()` gets `[]`.
126 */
127 protected locatorForAll<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>[]>;
128 /**
129 * Flushes change detection and async tasks in the Angular zone.
130 * In most cases it should not be necessary to call this manually. However, there may be some edge
131 * cases where it is needed to fully flush animation events.
132 */
133 protected forceStabilize(): Promise<void>;
134 /**
135 * Waits for all scheduled or running async tasks to complete. This allows harness
136 * authors to wait for async tasks outside of the Angular zone.
137 */
138 protected waitForTasksOutsideAngular(): Promise<void>;
139}
140
141/** Constructor for a ComponentHarness subclass. */
142export declare interface ComponentHarnessConstructor<T extends ComponentHarness> {
143 new (locatorFactory: LocatorFactory): T;
144 /**
145 * `ComponentHarness` subclasses must specify a static `hostSelector` property that is used to
146 * find the host element for the corresponding component. This property should match the selector
147 * for the Angular component.
148 */
149 hostSelector: string;
150}
151
152/**
153 * Base class for component harnesses that authors should extend if they anticipate that consumers
154 * of the harness may want to access other harnesses within the `<ng-content>` of the component.
155 */
156export declare abstract class ContentContainerComponentHarness<S extends string = string> extends ComponentHarness implements HarnessLoader {
157 getChildLoader(selector: S): Promise<HarnessLoader>;
158 getAllChildLoaders(selector: S): Promise<HarnessLoader[]>;
159 getHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T>;
160 getHarnessOrNull<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T | null>;
161 getAllHarnesses<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T[]>;
162 hasHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<boolean>;
163 /**
164 * Gets the root harness loader from which to start
165 * searching for content contained by this harness.
166 */
167 protected getRootHarnessLoader(): Promise<HarnessLoader>;
168}
169
170
171/**
172 * Dimensions for element size and its position relative to the viewport.
173 */
174export declare interface ElementDimensions {
175 top: number;
176 left: number;
177 width: number;
178 height: number;
179}
180
181/** Data that can be attached to a custom event dispatched from a `TestElement`. */
182export declare type EventData = string | number | boolean | Function | undefined | null | EventData[] | {
183 [key: string]: EventData;
184};
185
186
187/**
188 * Returns an error which reports that no keys have been specified.
189 * @docs-private
190 */
191export declare function getNoKeysSpecifiedError(): Error;
192
193
194/**
195 * Gets text of element excluding certain selectors within the element.
196 * @param element Element to get text from,
197 * @param excludeSelector Selector identifying which elements to exclude,
198 */
199export declare function _getTextWithExcludedElements(element: Element, excludeSelector: string): string;
200
201/**
202 * Allows a test `HarnessEnvironment` to install its own handler for auto change detection status
203 * changes.
204 * @param handler The handler for the auto change detection status.
205 */
206export declare function handleAutoChangeDetectionStatus(handler: (status: AutoChangeDetectionStatus) => void): void;
207
208/**
209 * Base harness environment class that can be extended to allow `ComponentHarness`es to be used in
210 * different test environments (e.g. testbed, protractor, etc.). This class implements the
211 * functionality of both a `HarnessLoader` and `LocatorFactory`. This class is generic on the raw
212 * element type, `E`, used by the particular test environment.
213 */
214export declare abstract class HarnessEnvironment<E> implements HarnessLoader, LocatorFactory {
215 protected rawRootElement: E;
216 get rootElement(): TestElement;
217 set rootElement(element: TestElement);
218 private _rootElement;
219 protected constructor(rawRootElement: E);
220 documentRootLocatorFactory(): LocatorFactory;
221 locatorFor<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>>;
222 locatorForOptional<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T> | null>;
223 locatorForAll<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>[]>;
224 rootHarnessLoader(): Promise<HarnessLoader>;
225 harnessLoaderFor(selector: string): Promise<HarnessLoader>;
226 harnessLoaderForOptional(selector: string): Promise<HarnessLoader | null>;
227 harnessLoaderForAll(selector: string): Promise<HarnessLoader[]>;
228 getHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T>;
229 getHarnessOrNull<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T | null>;
230 getAllHarnesses<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T[]>;
231 hasHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<boolean>;
232 getChildLoader(selector: string): Promise<HarnessLoader>;
233 getAllChildLoaders(selector: string): Promise<HarnessLoader[]>;
234 /** Creates a `ComponentHarness` for the given harness type with the given raw host element. */
235 protected createComponentHarness<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T>, element: E): T;
236 abstract forceStabilize(): Promise<void>;
237 abstract waitForTasksOutsideAngular(): Promise<void>;
238 /** Gets the root element for the document. */
239 protected abstract getDocumentRoot(): E;
240 /** Creates a `TestElement` from a raw element. */
241 protected abstract createTestElement(element: E): TestElement;
242 /** Creates a `HarnessLoader` rooted at the given raw element. */
243 protected abstract createEnvironment(element: E): HarnessEnvironment<E>;
244 /**
245 * Gets a list of all elements matching the given selector under this environment's root element.
246 */
247 protected abstract getAllRawElements(selector: string): Promise<E[]>;
248 /**
249 * Matches the given raw elements with the given list of element and harness queries to produce a
250 * list of matched harnesses and test elements.
251 */
252 private _getAllHarnessesAndTestElements;
253 /**
254 * Check whether the given query matches the given element, if it does return the matched
255 * `TestElement` or `ComponentHarness`, if it does not, return null. In cases where the caller
256 * knows for sure that the query matches the element's selector, `skipSelectorCheck` can be used
257 * to skip verification and optimize performance.
258 */
259 private _getQueryResultForElement;
260}
261
262/**
263 * Interface used to load ComponentHarness objects. This interface is used by test authors to
264 * instantiate `ComponentHarness`es.
265 */
266export declare interface HarnessLoader {
267 /**
268 * Searches for an element with the given selector under the current instances's root element,
269 * and returns a `HarnessLoader` rooted at the matching element. If multiple elements match the
270 * selector, the first is used. If no elements match, an error is thrown.
271 * @param selector The selector for the root element of the new `HarnessLoader`
272 * @return A `HarnessLoader` rooted at the element matching the given selector.
273 * @throws If a matching element can't be found.
274 */
275 getChildLoader(selector: string): Promise<HarnessLoader>;
276 /**
277 * Searches for all elements with the given selector under the current instances's root element,
278 * and returns an array of `HarnessLoader`s, one for each matching element, rooted at that
279 * element.
280 * @param selector The selector for the root element of the new `HarnessLoader`
281 * @return A list of `HarnessLoader`s, one for each matching element, rooted at that element.
282 */
283 getAllChildLoaders(selector: string): Promise<HarnessLoader[]>;
284 /**
285 * Searches for an instance of the component corresponding to the given harness type under the
286 * `HarnessLoader`'s root element, and returns a `ComponentHarness` for that instance. If multiple
287 * matching components are found, a harness for the first one is returned. If no matching
288 * component is found, an error is thrown.
289 * @param query A query for a harness to create
290 * @return An instance of the given harness type
291 * @throws If a matching component instance can't be found.
292 */
293 getHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T>;
294 /**
295 * Searches for an instance of the component corresponding to the given harness type under the
296 * `HarnessLoader`'s root element, and returns a `ComponentHarness` for that instance. If multiple
297 * matching components are found, a harness for the first one is returned. If no matching
298 * component is found, null is returned.
299 * @param query A query for a harness to create
300 * @return An instance of the given harness type (or null if not found).
301 */
302 getHarnessOrNull<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T | null>;
303 /**
304 * Searches for all instances of the component corresponding to the given harness type under the
305 * `HarnessLoader`'s root element, and returns a list `ComponentHarness` for each instance.
306 * @param query A query for a harness to create
307 * @return A list instances of the given harness type.
308 */
309 getAllHarnesses<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<T[]>;
310 /**
311 * Searches for an instance of the component corresponding to the given harness type under the
312 * `HarnessLoader`'s root element, and returns a boolean indicating if any were found.
313 * @param query A query for a harness to create
314 * @return A boolean indicating if an instance was found.
315 */
316 hasHarness<T extends ComponentHarness>(query: HarnessQuery<T>): Promise<boolean>;
317}
318
319/**
320 * A class used to associate a ComponentHarness class with predicates functions that can be used to
321 * filter instances of the class.
322 */
323export declare class HarnessPredicate<T extends ComponentHarness> {
324 harnessType: ComponentHarnessConstructor<T>;
325 private _predicates;
326 private _descriptions;
327 private _ancestor;
328 constructor(harnessType: ComponentHarnessConstructor<T>, options: BaseHarnessFilters);
329 /**
330 * Checks if the specified nullable string value matches the given pattern.
331 * @param value The nullable string value to check, or a Promise resolving to the
332 * nullable string value.
333 * @param pattern The pattern the value is expected to match. If `pattern` is a string,
334 * `value` is expected to match exactly. If `pattern` is a regex, a partial match is
335 * allowed. If `pattern` is `null`, the value is expected to be `null`.
336 * @return Whether the value matches the pattern.
337 */
338 static stringMatches(value: string | null | Promise<string | null>, pattern: string | RegExp | null): Promise<boolean>;
339 /**
340 * Adds a predicate function to be run against candidate harnesses.
341 * @param description A description of this predicate that may be used in error messages.
342 * @param predicate An async predicate function.
343 * @return this (for method chaining).
344 */
345 add(description: string, predicate: AsyncPredicate<T>): this;
346 /**
347 * Adds a predicate function that depends on an option value to be run against candidate
348 * harnesses. If the option value is undefined, the predicate will be ignored.
349 * @param name The name of the option (may be used in error messages).
350 * @param option The option value.
351 * @param predicate The predicate function to run if the option value is not undefined.
352 * @return this (for method chaining).
353 */
354 addOption<O>(name: string, option: O | undefined, predicate: AsyncOptionPredicate<T, O>): this;
355 /**
356 * Filters a list of harnesses on this predicate.
357 * @param harnesses The list of harnesses to filter.
358 * @return A list of harnesses that satisfy this predicate.
359 */
360 filter(harnesses: T[]): Promise<T[]>;
361 /**
362 * Evaluates whether the given harness satisfies this predicate.
363 * @param harness The harness to check
364 * @return A promise that resolves to true if the harness satisfies this predicate,
365 * and resolves to false otherwise.
366 */
367 evaluate(harness: T): Promise<boolean>;
368 /** Gets a description of this predicate for use in error messages. */
369 getDescription(): string;
370 /** Gets the selector used to find candidate elements. */
371 getSelector(): string;
372 /** Adds base options common to all harness types. */
373 private _addBaseOptions;
374}
375
376/**
377 * A query for a `ComponentHarness`, which is expressed as either a `ComponentHarnessConstructor` or
378 * a `HarnessPredicate`.
379 */
380export declare type HarnessQuery<T extends ComponentHarness> = ComponentHarnessConstructor<T> | HarnessPredicate<T>;
381
382/**
383 * Interface used to create asynchronous locator functions used find elements and component
384 * harnesses. This interface is used by `ComponentHarness` authors to create locator functions for
385 * their `ComponentHarness` subclass.
386 */
387export declare interface LocatorFactory {
388 /** Gets a locator factory rooted at the document root. */
389 documentRootLocatorFactory(): LocatorFactory;
390 /** The root element of this `LocatorFactory` as a `TestElement`. */
391 rootElement: TestElement;
392 /**
393 * Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
394 * or element under the root element of this `LocatorFactory`.
395 * @param queries A list of queries specifying which harnesses and elements to search for:
396 * - A `string` searches for elements matching the CSS selector specified by the string.
397 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
398 * given class.
399 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
400 * predicate.
401 * @return An asynchronous locator function that searches for and returns a `Promise` for the
402 * first element or harness matching the given search criteria. Matches are ordered first by
403 * order in the DOM, and second by order in the queries list. If no matches are found, the
404 * `Promise` rejects. The type that the `Promise` resolves to is a union of all result types for
405 * each query.
406 *
407 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
408 * `DivHarness.hostSelector === 'div'`:
409 * - `await lf.locatorFor(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
410 * - `await lf.locatorFor('div', DivHarness)()` gets a `TestElement` instance for `#d1`
411 * - `await lf.locatorFor('span')()` throws because the `Promise` rejects.
412 */
413 locatorFor<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>>;
414 /**
415 * Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
416 * or element under the root element of this `LocatorFactory`.
417 * @param queries A list of queries specifying which harnesses and elements to search for:
418 * - A `string` searches for elements matching the CSS selector specified by the string.
419 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
420 * given class.
421 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
422 * predicate.
423 * @return An asynchronous locator function that searches for and returns a `Promise` for the
424 * first element or harness matching the given search criteria. Matches are ordered first by
425 * order in the DOM, and second by order in the queries list. If no matches are found, the
426 * `Promise` is resolved with `null`. The type that the `Promise` resolves to is a union of all
427 * result types for each query or null.
428 *
429 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
430 * `DivHarness.hostSelector === 'div'`:
431 * - `await lf.locatorForOptional(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
432 * - `await lf.locatorForOptional('div', DivHarness)()` gets a `TestElement` instance for `#d1`
433 * - `await lf.locatorForOptional('span')()` gets `null`.
434 */
435 locatorForOptional<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T> | null>;
436 /**
437 * Creates an asynchronous locator function that can be used to find `ComponentHarness` instances
438 * or elements under the root element of this `LocatorFactory`.
439 * @param queries A list of queries specifying which harnesses and elements to search for:
440 * - A `string` searches for elements matching the CSS selector specified by the string.
441 * - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
442 * given class.
443 * - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
444 * predicate.
445 * @return An asynchronous locator function that searches for and returns a `Promise` for all
446 * elements and harnesses matching the given search criteria. Matches are ordered first by
447 * order in the DOM, and second by order in the queries list. If an element matches more than
448 * one `ComponentHarness` class, the locator gets an instance of each for the same element. If
449 * an element matches multiple `string` selectors, only one `TestElement` instance is returned
450 * for that element. The type that the `Promise` resolves to is an array where each element is
451 * the union of all result types for each query.
452 *
453 * e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
454 * `DivHarness.hostSelector === 'div'` and `IdIsD1Harness.hostSelector === '#d1'`:
455 * - `await lf.locatorForAll(DivHarness, 'div')()` gets `[
456 * DivHarness, // for #d1
457 * TestElement, // for #d1
458 * DivHarness, // for #d2
459 * TestElement // for #d2
460 * ]`
461 * - `await lf.locatorForAll('div', '#d1')()` gets `[
462 * TestElement, // for #d1
463 * TestElement // for #d2
464 * ]`
465 * - `await lf.locatorForAll(DivHarness, IdIsD1Harness)()` gets `[
466 * DivHarness, // for #d1
467 * IdIsD1Harness, // for #d1
468 * DivHarness // for #d2
469 * ]`
470 * - `await lf.locatorForAll('span')()` gets `[]`.
471 */
472 locatorForAll<T extends (HarnessQuery<any> | string)[]>(...queries: T): AsyncFactoryFn<LocatorFnResult<T>[]>;
473 /** @return A `HarnessLoader` rooted at the root element of this `LocatorFactory`. */
474 rootHarnessLoader(): Promise<HarnessLoader>;
475 /**
476 * Gets a `HarnessLoader` instance for an element under the root of this `LocatorFactory`.
477 * @param selector The selector for the root element.
478 * @return A `HarnessLoader` rooted at the first element matching the given selector.
479 * @throws If no matching element is found for the given selector.
480 */
481 harnessLoaderFor(selector: string): Promise<HarnessLoader>;
482 /**
483 * Gets a `HarnessLoader` instance for an element under the root of this `LocatorFactory`
484 * @param selector The selector for the root element.
485 * @return A `HarnessLoader` rooted at the first element matching the given selector, or null if
486 * no matching element is found.
487 */
488 harnessLoaderForOptional(selector: string): Promise<HarnessLoader | null>;
489 /**
490 * Gets a list of `HarnessLoader` instances, one for each matching element.
491 * @param selector The selector for the root element.
492 * @return A list of `HarnessLoader`, one rooted at each element matching the given selector.
493 */
494 harnessLoaderForAll(selector: string): Promise<HarnessLoader[]>;
495 /**
496 * Flushes change detection and async tasks captured in the Angular zone.
497 * In most cases it should not be necessary to call this manually. However, there may be some edge
498 * cases where it is needed to fully flush animation events.
499 */
500 forceStabilize(): Promise<void>;
501 /**
502 * Waits for all scheduled or running async tasks to complete. This allows harness
503 * authors to wait for async tasks outside of the Angular zone.
504 */
505 waitForTasksOutsideAngular(): Promise<void>;
506}
507
508/**
509 * The result type obtained when searching using a particular list of queries. This type depends on
510 * the particular items being queried.
511 * - If one of the queries is for a `ComponentHarnessConstructor<C1>`, it means that the result
512 * might be a harness of type `C1`
513 * - If one of the queries is for a `HarnessPredicate<C2>`, it means that the result might be a
514 * harness of type `C2`
515 * - If one of the queries is for a `string`, it means that the result might be a `TestElement`.
516 *
517 * Since we don't know for sure which query will match, the result type if the union of the types
518 * for all possible results.
519 *
520 * e.g.
521 * The type:
522 * `LocatorFnResult&lt;[
523 * ComponentHarnessConstructor&lt;MyHarness&gt;,
524 * HarnessPredicate&lt;MyOtherHarness&gt;,
525 * string
526 * ]&gt;`
527 * is equivalent to:
528 * `MyHarness | MyOtherHarness | TestElement`.
529 */
530export declare type LocatorFnResult<T extends (HarnessQuery<any> | string)[]> = {
531 [I in keyof T]: T[I] extends new (...args: any[]) => infer C ? C : T[I] extends {
532 harnessType: new (...args: any[]) => infer C;
533 } ? C : T[I] extends string ? TestElement : never;
534}[number];
535
536/**
537 * Disables the harness system's auto change detection for the duration of the given function.
538 * @param fn The function to disable auto change detection for.
539 * @return The result of the given function.
540 */
541export declare function manualChangeDetection<T>(fn: () => Promise<T>): Promise<T>;
542
543/** Modifier keys that may be held while typing. */
544export declare interface ModifierKeys {
545 control?: boolean;
546 alt?: boolean;
547 shift?: boolean;
548 meta?: boolean;
549}
550
551/**
552 * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change
553 * detection over the entire operation such that change detection occurs exactly once before
554 * resolving the values and once after.
555 * @param values A getter for the async values to resolve in parallel with batched change detection.
556 * @return The resolved values.
557 */
558export declare function parallel<T1, T2, T3, T4, T5>(values: () => [
559T1 | PromiseLike<T1>,
560T2 | PromiseLike<T2>,
561T3 | PromiseLike<T3>,
562T4 | PromiseLike<T4>,
563T5 | PromiseLike<T5>
564]): Promise<[T1, T2, T3, T4, T5]>;
565
566/**
567 * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change
568 * detection over the entire operation such that change detection occurs exactly once before
569 * resolving the values and once after.
570 * @param values A getter for the async values to resolve in parallel with batched change detection.
571 * @return The resolved values.
572 */
573export declare function parallel<T1, T2, T3, T4>(values: () => [
574T1 | PromiseLike<T1>,
575T2 | PromiseLike<T2>,
576T3 | PromiseLike<T3>,
577T4 | PromiseLike<T4>
578]): Promise<[T1, T2, T3, T4]>;
579
580/**
581 * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change
582 * detection over the entire operation such that change detection occurs exactly once before
583 * resolving the values and once after.
584 * @param values A getter for the async values to resolve in parallel with batched change detection.
585 * @return The resolved values.
586 */
587export declare function parallel<T1, T2, T3>(values: () => [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
588
589/**
590 * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change
591 * detection over the entire operation such that change detection occurs exactly once before
592 * resolving the values and once after.
593 * @param values A getter for the async values to resolve in parallel with batched change detection.
594 * @return The resolved values.
595 */
596export declare function parallel<T1, T2>(values: () => [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
597
598/**
599 * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change
600 * detection over the entire operation such that change detection occurs exactly once before
601 * resolving the values and once after.
602 * @param values A getter for the async values to resolve in parallel with batched change detection.
603 * @return The resolved values.
604 */
605export declare function parallel<T>(values: () => (T | PromiseLike<T>)[]): Promise<T[]>;
606
607/** Allows a `HarnessEnvironment` to stop handling auto change detection status changes. */
608export declare function stopHandlingAutoChangeDetectionStatus(): void;
609
610/**
611 * This acts as a common interface for DOM elements across both unit and e2e tests. It is the
612 * interface through which the ComponentHarness interacts with the component's DOM.
613 */
614export declare interface TestElement {
615 /** Blur the element. */
616 blur(): Promise<void>;
617 /** Clear the element's input (for input and textarea elements only). */
618 clear(): Promise<void>;
619 /**
620 * Click the element at the default location for the current environment. If you need to guarantee
621 * the element is clicked at a specific location, consider using `click('center')` or
622 * `click(x, y)` instead.
623 */
624 click(modifiers?: ModifierKeys): Promise<void>;
625 /** Click the element at the element's center. */
626 click(location: 'center', modifiers?: ModifierKeys): Promise<void>;
627 /**
628 * Click the element at the specified coordinates relative to the top-left of the element.
629 * @param relativeX Coordinate within the element, along the X-axis at which to click.
630 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
631 * @param modifiers Modifier keys held while clicking
632 */
633 click(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
634 /**
635 * Right clicks on the element at the specified coordinates relative to the top-left of it.
636 * @param relativeX Coordinate within the element, along the X-axis at which to click.
637 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
638 * @param modifiers Modifier keys held while clicking
639 */
640 rightClick(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
641 /** Focus the element. */
642 focus(): Promise<void>;
643 /** Get the computed value of the given CSS property for the element. */
644 getCssValue(property: string): Promise<string>;
645 /** Hovers the mouse over the element. */
646 hover(): Promise<void>;
647 /** Moves the mouse away from the element. */
648 mouseAway(): Promise<void>;
649 /**
650 * Sends the given string to the input as a series of key presses. Also fires input events
651 * and attempts to add the string to the Element's value. Note that some environments cannot
652 * reproduce native browser behavior for keyboard shortcuts such as Tab, Ctrl + A, etc.
653 * @throws An error if no keys have been specified.
654 */
655 sendKeys(...keys: (string | TestKey)[]): Promise<void>;
656 /**
657 * Sends the given string to the input as a series of key presses. Also fires input
658 * events and attempts to add the string to the Element's value.
659 * @throws An error if no keys have been specified.
660 */
661 sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
662 /**
663 * Gets the text from the element.
664 * @param options Options that affect what text is included.
665 */
666 text(options?: TextOptions): Promise<string>;
667 /**
668 * Sets the value of a `contenteditable` element.
669 * @param value Value to be set on the element.
670 * @breaking-change 16.0.0 Will become a required method.
671 */
672 setContenteditableValue?(value: string): Promise<void>;
673 /** Gets the value for the given attribute from the element. */
674 getAttribute(name: string): Promise<string | null>;
675 /** Checks whether the element has the given class. */
676 hasClass(name: string): Promise<boolean>;
677 /** Gets the dimensions of the element. */
678 getDimensions(): Promise<ElementDimensions>;
679 /** Gets the value of a property of an element. */
680 getProperty<T = any>(name: string): Promise<T>;
681 /** Checks whether this element matches the given selector. */
682 matchesSelector(selector: string): Promise<boolean>;
683 /** Checks whether the element is focused. */
684 isFocused(): Promise<boolean>;
685 /** Sets the value of a property of an input. */
686 setInputValue(value: string): Promise<void>;
687 /** Selects the options at the specified indexes inside of a native `select` element. */
688 selectOptions(...optionIndexes: number[]): Promise<void>;
689 /**
690 * Dispatches an event with a particular name.
691 * @param name Name of the event to be dispatched.
692 */
693 dispatchEvent(name: string, data?: Record<string, EventData>): Promise<void>;
694}
695
696/** An enum of non-text keys that can be used with the `sendKeys` method. */
697export declare enum TestKey {
698 BACKSPACE = 0,
699 TAB = 1,
700 ENTER = 2,
701 SHIFT = 3,
702 CONTROL = 4,
703 ALT = 5,
704 ESCAPE = 6,
705 PAGE_UP = 7,
706 PAGE_DOWN = 8,
707 END = 9,
708 HOME = 10,
709 LEFT_ARROW = 11,
710 UP_ARROW = 12,
711 RIGHT_ARROW = 13,
712 DOWN_ARROW = 14,
713 INSERT = 15,
714 DELETE = 16,
715 F1 = 17,
716 F2 = 18,
717 F3 = 19,
718 F4 = 20,
719 F5 = 21,
720 F6 = 22,
721 F7 = 23,
722 F8 = 24,
723 F9 = 25,
724 F10 = 26,
725 F11 = 27,
726 F12 = 28,
727 META = 29
728}
729
730export declare interface TextOptions {
731 /** Optional selector for elements to exclude. */
732 exclude?: string;
733}
734
735export { }