Skip to content

Commit 78fa003

Browse files
committed
export text filtering from cdk/testing
1 parent 0a6a599 commit 78fa003

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

src/cdk/testing/protractor/protractor-element.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
*/
88

99
import {
10+
_getTextWithExcludedElements,
1011
ElementDimensions,
1112
ModifierKeys,
1213
TestElement,
13-
TestKey, TextOptions
14+
TestKey,
15+
TextOptions
1416
} from '@angular/cdk/testing';
1517
import {browser, ElementFinder, Key} from 'protractor';
16-
import {getTextWithExcludedElements} from '../text-filtering';
1718

1819
/** Maps the `TestKey` constants to Protractor's `Key` constants. */
1920
const keyMap = {
@@ -137,7 +138,7 @@ export class ProtractorElement implements TestElement {
137138

138139
async text(options?: TextOptions): Promise<string> {
139140
if (options?.exclude) {
140-
return browser.executeScript(getTextWithExcludedElements, this.element, options.exclude);
141+
return browser.executeScript(_getTextWithExcludedElements, this.element, options.exclude);
141142
}
142143
return this.element.getText();
143144
}

src/cdk/testing/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './component-harness';
1010
export * from './harness-environment';
1111
export * from './test-element';
1212
export * from './element-dimensions';
13+
export * from './text-filtering';

src/cdk/testing/testbed/unit-test-element.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import * as keyCodes from '@angular/cdk/keycodes';
1010
import {
11+
_getTextWithExcludedElements,
1112
ElementDimensions,
1213
ModifierKeys,
1314
TestElement,
14-
TestKey, TextOptions
15+
TestKey,
16+
TextOptions
1517
} from '@angular/cdk/testing';
1618
import {
1719
clearElement,
@@ -22,7 +24,6 @@ import {
2224
triggerFocus,
2325
typeInElement,
2426
} from './fake-events';
25-
import {getTextWithExcludedElements} from '../text-filtering';
2627

2728
/** Maps `TestKey` constants to the `keyCode` and `key` values used by native browser events. */
2829
const keyMap = {
@@ -135,7 +136,7 @@ export class UnitTestElement implements TestElement {
135136
async text(options?: TextOptions): Promise<string> {
136137
await this._stabilize();
137138
if (options?.exclude) {
138-
return getTextWithExcludedElements(this.element, options.exclude);
139+
return _getTextWithExcludedElements(this.element, options.exclude);
139140
}
140141
return (this.element.textContent || '').trim();
141142
}

src/cdk/testing/text-filtering.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
19
/**
210
* Gets text of element excluding certain selectors within the element.
311
* @param element Element to get text from,
412
* @param excludeSelector Selector identifying which elements to exclude,
513
*/
6-
export function getTextWithExcludedElements(element: Element, excludeSelector: string) {
14+
export function _getTextWithExcludedElements(element: Element, excludeSelector: string) {
715
const clone = element.cloneNode(true) as Element;
816
const exclusions = clone.querySelectorAll(excludeSelector);
917
for (let i = 0; i < exclusions.length; i++) {

tools/public_api_guard/cdk/testing.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export declare function _getTextWithExcludedElements(element: Element, excludeSelector: string): string;
2+
13
export declare type AsyncFactoryFn<T> = () => Promise<T>;
24

35
export declare type AsyncOptionPredicate<T, O> = (item: T, option: O) => Promise<boolean>;

0 commit comments

Comments
 (0)