diff --git a/src/__tests__/screen.js b/src/__tests__/screen.js index 2fbe0970..7c57de4a 100644 --- a/src/__tests__/screen.js +++ b/src/__tests__/screen.js @@ -64,6 +64,15 @@ test('logs Playground URL that are passed as element', () => { `) }) +test('returns Playground URL that are passed as element', () => { + const playGroundUrl = screen.logTestingPlaygroundURL( + render(`

Sign up

`).container, + ) + expect(playGroundUrl).toMatchInlineSnapshot( + 'https://testing-playground.com/#markup=DwCwjAfAyglg5gOwATAKYFsIFcAOwD0GEB4EQA', + ) +}) + test('exposes debug method', () => { renderIntoDocument( `multi-test
multi-test
`, diff --git a/src/screen.ts b/src/screen.ts index caae921d..0b3cc8c8 100644 --- a/src/screen.ts +++ b/src/screen.ts @@ -39,9 +39,9 @@ const logTestingPlaygroundURL = (element = getDocument().body) => { console.log(`The provided element doesn't have any children.`) return } - console.log( - `Open this URL in your browser\n\n${getPlaygroundUrl(element.innerHTML)}`, - ) + const playgroundUrl = getPlaygroundUrl(element.innerHTML) + console.log(`Open this URL in your browser\n\n${playgroundUrl}`) + return playgroundUrl } const initialValue = {debug, logTestingPlaygroundURL} diff --git a/types/screen.d.ts b/types/screen.d.ts index 4013af4a..c2f1b02e 100644 --- a/types/screen.d.ts +++ b/types/screen.d.ts @@ -13,10 +13,10 @@ export type Screen = BoundFunctions & { options?: OptionsReceived, ) => void /** - * Convenience function for `Testing Playground` which logs URL that + * Convenience function for `Testing Playground` which logs and returns the URL that * can be opened in a browser */ - logTestingPlaygroundURL: (element?: Element | HTMLDocument) => void + logTestingPlaygroundURL: (element?: Element | HTMLDocument) => string } export const screen: Screen