From 6d6312f7dc463820a6e248b99fbb61cb64aea822 Mon Sep 17 00:00:00 2001 From: Lirlev48 <58209233+Lirlev48@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:06:36 +0300 Subject: [PATCH] feat: add a return value from logTestingPlaygroundURL (#1144) * Liron * Liron * Update types/screen.d.ts Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> * Update types/screen.d.ts Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> * Liron Co-authored-by: lironlevy Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Co-authored-by: Matan Borenkraout --- src/__tests__/screen.js | 9 +++++++++ src/screen.ts | 6 +++--- types/screen.d.ts | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) 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