@@ -7,15 +7,15 @@ import {getDocument} from './helpers'
7
7
function unindent ( string ) {
8
8
// remove white spaces first, to save a few bytes.
9
9
// testing-playground will reformat on load any ways.
10
- return ( string || '' ) . replace ( / [ \t ] * [ \n ] [ \t ] * / g, '\n' )
10
+ return string . replace ( / [ \t ] * [ \n ] [ \t ] * / g, '\n' )
11
11
}
12
12
13
13
function encode ( value ) {
14
14
return compressToEncodedURIComponent ( unindent ( value ) )
15
15
}
16
16
17
- function getPlaygroundUrl ( element ) {
18
- return `https://testing-playground.com/#markup=${ encode ( element . innerHTML ) } `
17
+ function getPlaygroundUrl ( markup ) {
18
+ return `https://testing-playground.com/#markup=${ encode ( markup ) } `
19
19
}
20
20
21
21
const debug = ( element , maxLength , options ) =>
@@ -24,7 +24,17 @@ const debug = (element, maxLength, options) =>
24
24
: logDOM ( element , maxLength , options )
25
25
26
26
const logTestingPlaygroundURL = ( element = getDocument ( ) . body ) => {
27
- console . log ( `Open this URL in your browser\n\n${ getPlaygroundUrl ( element ) } ` )
27
+ if ( ! element || ! ( 'innerHTML' in element ) ) {
28
+ console . log ( `The element you're providing isn't a valid DOM element.` )
29
+ return
30
+ }
31
+ if ( ! element . innerHTML ) {
32
+ console . log ( `The provided element doesn't have any children.` )
33
+ return
34
+ }
35
+ console . log (
36
+ `Open this URL in your browser\n\n${ getPlaygroundUrl ( element . innerHTML ) } ` ,
37
+ )
28
38
}
29
39
30
40
const initialValue = { debug, logTestingPlaygroundURL}
0 commit comments