File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ export function inShadow ( ele : Node ) {
2+ return ele ?. getRootNode ( ) !== ele ?. ownerDocument ;
3+ }
4+
5+ export function getShadowRoot ( ele : Node ) {
6+ return inShadow ( ele ) ? ele ?. getRootNode ( ) : null ;
7+ }
Original file line number Diff line number Diff line change 1+ import { getShadowRoot } from '../src/Dom/shadow' ;
2+
3+ describe ( 'shadow' , ( ) => {
4+ describe ( 'getShadowRoot' , ( ) => {
5+ it ( 'show work' , ( ) => {
6+ const shadowRoot = document . createElement ( 'div' ) ;
7+ document . body . appendChild ( shadowRoot ) ;
8+
9+ const shadow = shadowRoot . attachShadow ( { mode : 'open' } ) ;
10+ const inShadowButton = document . createElement ( 'button' ) ;
11+ shadow . appendChild ( inShadowButton ) ;
12+
13+ expect ( getShadowRoot ( inShadowButton ) ) . toBe ( shadow ) ;
14+ } ) ;
15+
16+ it ( 'show return null' , ( ) => {
17+ const button = document . createElement ( 'button' ) ;
18+ document . body . appendChild ( button ) ;
19+
20+ expect ( getShadowRoot ( button ) ) . toBeNull ( ) ;
21+ } ) ;
22+ } ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments