Skip to content

Commit 07aa3a1

Browse files
Add runtime check back in logTestingPlaygroundUrl
1 parent 4cfb5c9 commit 07aa3a1

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/__tests__/screen.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ test('logs messsage when element is not a valid HTML', () => {
4646
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(
4747
`"The element you're providing isn't a valid DOM element."`,
4848
)
49+
console.log.mockClear()
50+
screen.logTestingPlaygroundURL({})
51+
expect(console.log).toHaveBeenCalledTimes(1)
52+
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(
53+
`"The element you're providing isn't a valid DOM element."`,
54+
)
4955
})
5056

5157
test('logs Playground URL that are passed as element', () => {

src/playground-helper.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ function encode(value: string) {
1111
}
1212

1313
function getPlaygroundUrl(element: Element) {
14-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15-
if (!element) {
16-
throw new Error(`The element you're providing isn't a valid DOM element.`)
17-
}
18-
1914
if (!element.innerHTML) {
2015
throw new Error(`The provided element doesn't have any children.`)
2116
}

src/screen.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const debug = (element, maxLength, options) =>
1010
: logDOM(element, maxLength, options)
1111

1212
const logTestingPlaygroundURL = (element = getDocument().body) => {
13+
if (!element || !('innerHTML' in element)) {
14+
console.log(`The element you're providing isn't a valid DOM element.`)
15+
return
16+
}
17+
1318
try {
1419
const url = getPlaygroundUrl(element)
1520
console.log(`Open this URL in your browser\n\n${url}`)

types/screen.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q> & {
1616
* Convenience function for `Testing Playground` which logs URL that
1717
* can be opened in a browser
1818
*/
19-
logTestingPlaygroundURL: (element?: Element) => void
19+
logTestingPlaygroundURL: (element?: Element | HTMLDocument) => void
2020
}
2121

2222
export const screen: Screen

0 commit comments

Comments
 (0)