Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a return value from logTestingPlaygroundURL #1144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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