UNPKG

8.54 kBTypeScriptView Raw
1import { ComponentFixture } from '@angular/core/testing';
2import { ComponentHarness } from '@angular/cdk/testing';
3import { ComponentHarnessConstructor } from '@angular/cdk/testing';
4import { ElementDimensions } from '@angular/cdk/testing';
5import { EventData } from '@angular/cdk/testing';
6import { HarnessEnvironment } from '@angular/cdk/testing';
7import { HarnessLoader } from '@angular/cdk/testing';
8import { ModifierKeys } from '@angular/cdk/testing';
9import { TestElement } from '@angular/cdk/testing';
10import { TestKey } from '@angular/cdk/testing';
11import { TextOptions } from '@angular/cdk/testing';
12
13/** A `HarnessEnvironment` implementation for Angular's Testbed. */
14export declare class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
15 private _fixture;
16 /** Whether the environment has been destroyed. */
17 private _destroyed;
18 /** Observable that emits whenever the test task state changes. */
19 private _taskState;
20 /** The options for this environment. */
21 private _options;
22 /** Environment stabilization callback passed to the created test elements. */
23 private _stabilizeCallback;
24 protected constructor(rawRootElement: Element, _fixture: ComponentFixture<unknown>, options?: TestbedHarnessEnvironmentOptions);
25 /** Creates a `HarnessLoader` rooted at the given fixture's root element. */
26 static loader(fixture: ComponentFixture<unknown>, options?: TestbedHarnessEnvironmentOptions): HarnessLoader;
27 /**
28 * Creates a `HarnessLoader` at the document root. This can be used if harnesses are
29 * located outside of a fixture (e.g. overlays appended to the document body).
30 */
31 static documentRootLoader(fixture: ComponentFixture<unknown>, options?: TestbedHarnessEnvironmentOptions): HarnessLoader;
32 /** Gets the native DOM element corresponding to the given TestElement. */
33 static getNativeElement(el: TestElement): Element;
34 /**
35 * Creates an instance of the given harness type, using the fixture's root element as the
36 * harness's host element. This method should be used when creating a harness for the root element
37 * of a fixture, as components do not have the correct selector when they are created as the root
38 * of the fixture.
39 */
40 static harnessForFixture<T extends ComponentHarness>(fixture: ComponentFixture<unknown>, harnessType: ComponentHarnessConstructor<T>, options?: TestbedHarnessEnvironmentOptions): Promise<T>;
41 /**
42 * Flushes change detection and async tasks captured in the Angular zone.
43 * In most cases it should not be necessary to call this manually. However, there may be some edge
44 * cases where it is needed to fully flush animation events.
45 */
46 forceStabilize(): Promise<void>;
47 /**
48 * Waits for all scheduled or running async tasks to complete. This allows harness
49 * authors to wait for async tasks outside of the Angular zone.
50 */
51 waitForTasksOutsideAngular(): Promise<void>;
52 /** Gets the root element for the document. */
53 protected getDocumentRoot(): Element;
54 /** Creates a `TestElement` from a raw element. */
55 protected createTestElement(element: Element): TestElement;
56 /** Creates a `HarnessLoader` rooted at the given raw element. */
57 protected createEnvironment(element: Element): HarnessEnvironment<Element>;
58 /**
59 * Gets a list of all elements matching the given selector under this environment's root element.
60 */
61 protected getAllRawElements(selector: string): Promise<Element[]>;
62}
63
64/** Options to configure the environment. */
65export declare interface TestbedHarnessEnvironmentOptions {
66 /** The query function used to find DOM elements. */
67 queryFn: (selector: string, root: Element) => Iterable<Element> | ArrayLike<Element>;
68}
69
70/** A `TestElement` implementation for unit tests. */
71export declare class UnitTestElement implements TestElement {
72 readonly element: Element;
73 private _stabilize;
74 constructor(element: Element, _stabilize: () => Promise<void>);
75 /** Blur the element. */
76 blur(): Promise<void>;
77 /** Clear the element's input (for input and textarea elements only). */
78 clear(): Promise<void>;
79 /**
80 * Click the element at the default location for the current environment. If you need to guarantee
81 * the element is clicked at a specific location, consider using `click('center')` or
82 * `click(x, y)` instead.
83 */
84 click(modifiers?: ModifierKeys): Promise<void>;
85 /** Click the element at the element's center. */
86 click(location: 'center', modifiers?: ModifierKeys): Promise<void>;
87 /**
88 * Click the element at the specified coordinates relative to the top-left of the element.
89 * @param relativeX Coordinate within the element, along the X-axis at which to click.
90 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
91 * @param modifiers Modifier keys held while clicking
92 */
93 click(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
94 /**
95 * Right clicks on the element at the specified coordinates relative to the top-left of it.
96 * @param relativeX Coordinate within the element, along the X-axis at which to click.
97 * @param relativeY Coordinate within the element, along the Y-axis at which to click.
98 * @param modifiers Modifier keys held while clicking
99 */
100 rightClick(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
101 /** Focus the element. */
102 focus(): Promise<void>;
103 /** Get the computed value of the given CSS property for the element. */
104 getCssValue(property: string): Promise<string>;
105 /** Hovers the mouse over the element. */
106 hover(): Promise<void>;
107 /** Moves the mouse away from the element. */
108 mouseAway(): Promise<void>;
109 /**
110 * Sends the given string to the input as a series of key presses. Also fires input events
111 * and attempts to add the string to the Element's value. Note that this cannot
112 * reproduce native browser behavior for keyboard shortcuts such as Tab, Ctrl + A, etc.
113 */
114 sendKeys(...keys: (string | TestKey)[]): Promise<void>;
115 /**
116 * Sends the given string to the input as a series of key presses. Also fires input events
117 * and attempts to add the string to the Element's value.
118 */
119 sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
120 /**
121 * Gets the text from the element.
122 * @param options Options that affect what text is included.
123 */
124 text(options?: TextOptions): Promise<string>;
125 /**
126 * Sets the value of a `contenteditable` element.
127 * @param value Value to be set on the element.
128 */
129 setContenteditableValue(value: string): Promise<void>;
130 /** Gets the value for the given attribute from the element. */
131 getAttribute(name: string): Promise<string | null>;
132 /** Checks whether the element has the given class. */
133 hasClass(name: string): Promise<boolean>;
134 /** Gets the dimensions of the element. */
135 getDimensions(): Promise<ElementDimensions>;
136 /** Gets the value of a property of an element. */
137 getProperty<T = any>(name: string): Promise<T>;
138 /** Sets the value of a property of an input. */
139 setInputValue(value: string): Promise<void>;
140 /** Selects the options at the specified indexes inside of a native `select` element. */
141 selectOptions(...optionIndexes: number[]): Promise<void>;
142 /** Checks whether this element matches the given selector. */
143 matchesSelector(selector: string): Promise<boolean>;
144 /** Checks whether the element is focused. */
145 isFocused(): Promise<boolean>;
146 /**
147 * Dispatches an event with a particular name.
148 * @param name Name of the event to be dispatched.
149 */
150 dispatchEvent(name: string, data?: Record<string, EventData>): Promise<void>;
151 /**
152 * Dispatches a pointer event on the current element if the browser supports it.
153 * @param name Name of the pointer event to be dispatched.
154 * @param clientX Coordinate of the user's pointer along the X axis.
155 * @param clientY Coordinate of the user's pointer along the Y axis.
156 * @param button Mouse button that should be pressed when dispatching the event.
157 */
158 private _dispatchPointerEventIfSupported;
159 /**
160 * Dispatches all the events that are part of a mouse event sequence
161 * and then emits a given primary event at the end, if speciifed.
162 */
163 private _dispatchMouseEventSequence;
164}
165
166export { }