Skip to content

Commit

Permalink
feat: add a return value from logTestingPlaygroundURL (#1144)
Browse files Browse the repository at this point in the history
* 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 <xvsciuvmcy27kruon22t3wvv2kfiqoguhmnnkebe6y5kmbl7vuzq>
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Co-authored-by: Matan Borenkraout <Matanbobi@gmail.com>
  • Loading branch information
3 people committed Jul 11, 2022
1 parent 7b10f73 commit 6d6312f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/screen.js
Expand Up @@ -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(`<h1>Sign <em>up</em></h1>`).container,
)
expect(playGroundUrl).toMatchInlineSnapshot(
'https://testing-playground.com/#markup=DwCwjAfAyglg5gOwATAKYFsIFcAOwD0GEB4EQA',
)
})

test('exposes debug method', () => {
renderIntoDocument(
`<button>test</button><span>multi-test</span><div>multi-test</div>`,
Expand Down
6 changes: 3 additions & 3 deletions src/screen.ts
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions types/screen.d.ts
Expand Up @@ -13,10 +13,10 @@ export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q> & {
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

0 comments on commit 6d6312f

Please sign in to comment.