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 4 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
1 change: 1 addition & 0 deletions src/screen.ts
Expand Up @@ -42,6 +42,7 @@ const logTestingPlaygroundURL = (element = getDocument().body) => {
console.log(
`Open this URL in your browser\n\n${getPlaygroundUrl(element.innerHTML)}`,
)
return getPlaygroundUrl(element.innerHTML)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, can we save the `getPlaygroundUrl in a const instead of calling the function twice? Not sure what the performance aspects for it, but better safe than sorry :)

}

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