File tree Expand file tree Collapse file tree 7 files changed +23
-26
lines changed
tools/public_api_guard/cdk Expand file tree Collapse file tree 7 files changed +23
-26
lines changed Original file line number Diff line number Diff line change
1
+ export function getTextWithExcludedElements ( element : Element , excludeSelector : string ) {
2
+ const clone = element . cloneNode ( true ) as Element ;
3
+ const exclusions = clone . querySelectorAll ( excludeSelector ) ;
4
+ for ( let i = 0 ; i < exclusions . length ; i ++ ) {
5
+ let child = exclusions [ i ] ;
6
+ child . parentNode ?. removeChild ( child ) ;
7
+ }
8
+ return ( clone . textContent || '' ) . trim ( ) ;
9
+ }
Original file line number Diff line number Diff line change 8
8
9
9
import {
10
10
ElementDimensions ,
11
- getTextWithExcludedElements ,
12
11
ModifierKeys ,
13
12
TestElement ,
14
13
TestKey
15
14
} from '@angular/cdk/testing' ;
16
15
import { browser , ElementFinder , Key } from 'protractor' ;
16
+ import { getTextWithExcludedElements } from '@angular/cdk/testing/dom-helpers' ;
17
17
18
18
/** Maps the `TestKey` constants to Protractor's `Key` constants. */
19
19
const keyMap = {
@@ -135,12 +135,11 @@ export class ProtractorElement implements TestElement {
135
135
return this . element . sendKeys ( ...keys ) ;
136
136
}
137
137
138
- async text ( options ?: { excludes ?: string } ) : Promise < string > {
139
- if ( options ?. excludes ) {
140
- return browser . executeScript ( getTextWithExcludedElements , this . element , options . excludes ) ;
141
- } else {
142
- return this . element . getText ( ) ;
138
+ async text ( options ?: { exclude ?: string } ) : Promise < string > {
139
+ if ( options ?. exclude ) {
140
+ return browser . executeScript ( getTextWithExcludedElements , this . element , options . excludes ;
143
141
}
142
+ return this . element . getText ( ) ;
144
143
}
145
144
146
145
async getAttribute ( name : string ) : Promise < string | null > {
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ export interface TestElement {
106
106
* @param options Options that affect what text is included
107
107
* exclude: A selector for elements whose text should be excluded from the result.
108
108
*/
109
- text ( options ?: { excludes ?: string } ) : Promise < string > ;
109
+ text ( options ?: { exclude ?: string } ) : Promise < string > ;
110
110
111
111
/** Gets the value for the given attribute from the element. */
112
112
getAttribute ( name : string ) : Promise < string | null > ;
@@ -132,13 +132,3 @@ export interface TestElement {
132
132
/** Checks whether the element is focused. */
133
133
isFocused ( ) : Promise < boolean > ;
134
134
}
135
-
136
- export function getTextWithExcludedElements ( element : Element , excludeSelector : string ) {
137
- const clone = element . cloneNode ( true ) as Element ;
138
- const exclusions = clone . querySelectorAll ( excludeSelector ) ;
139
- for ( let i = 0 ; i < exclusions . length ; i ++ ) {
140
- let child = exclusions [ i ] ;
141
- child . parentNode ?. removeChild ( child ) ;
142
- }
143
- return ( clone . textContent || '' ) . trim ( ) ;
144
- }
Original file line number Diff line number Diff line change 9
9
import * as keyCodes from '@angular/cdk/keycodes' ;
10
10
import {
11
11
ElementDimensions ,
12
- getTextWithExcludedElements ,
13
12
ModifierKeys ,
14
13
TestElement ,
15
14
TestKey
@@ -23,6 +22,7 @@ import {
23
22
triggerFocus ,
24
23
typeInElement ,
25
24
} from './fake-events' ;
25
+ import { getTextWithExcludedElements } from '@angular/cdk/testing/dom-helpers' ;
26
26
27
27
/** Maps `TestKey` constants to the `keyCode` and `key` values used by native browser events. */
28
28
const keyMap = {
@@ -132,13 +132,12 @@ export class UnitTestElement implements TestElement {
132
132
await this . _stabilize ( ) ;
133
133
}
134
134
135
- async text ( options ?: { excludes ?: string } ) : Promise < string > {
135
+ async text ( options ?: { exclude ?: string } ) : Promise < string > {
136
136
await this . _stabilize ( ) ;
137
- if ( options ?. excludes ) {
138
- return getTextWithExcludedElements ( this . element , options . excludes ) ;
139
- } else {
140
- return ( this . element . textContent || '' ) . trim ( ) ;
137
+ if ( options ?. exclude ) {
138
+ return getTextWithExcludedElements ( this . element , options . exclude ) ;
141
139
}
140
+ return ( this . element . textContent || '' ) . trim ( ) ;
142
141
}
143
142
144
143
async getAttribute ( name : string ) : Promise < string | null > {
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ export interface TestElement {
134
134
sendKeys ( modifiers : ModifierKeys , ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
135
135
setInputValue ?( value : string ) : Promise < void > ;
136
136
text ( options ?: {
137
- excludes ?: string ;
137
+ exclude ?: string ;
138
138
} ) : Promise < string > ;
139
139
}
140
140
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export declare class ProtractorElement implements TestElement {
18
18
sendKeys ( modifiers : ModifierKeys , ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
19
19
setInputValue ( value : string ) : Promise < void > ;
20
20
text ( options ?: {
21
- excludes ?: string ;
21
+ exclude ?: string ;
22
22
} ) : Promise < string > ;
23
23
}
24
24
Original file line number Diff line number Diff line change @@ -35,6 +35,6 @@ export declare class UnitTestElement implements TestElement {
35
35
sendKeys ( modifiers : ModifierKeys , ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
36
36
setInputValue ( value : string ) : Promise < void > ;
37
37
text ( options ?: {
38
- excludes ?: string ;
38
+ exclude ?: string ;
39
39
} ) : Promise < string > ;
40
40
}
You can’t perform that action at this time.
0 commit comments