-
Notifications
You must be signed in to change notification settings - Fork 466
Closed
Description
Describe the feature you'd like:
Hey everyone 😄
I'd like to when using the screen object to be able to use custom queries previously created with the buildQueries helper.
Suggested implementation:
To avoid potential breaking changes and keeping screen as an object, I'd suggest creating an initializeScreen function that would take a custom queries object as a parameter and return a new screen object.
- This function would take the current code assigned to the screen object and return a new screen object every time it was called.
- We could also use it to instantiate the default screen.
Regarding implementation, I'd say it would be like this:
import * as defaultQueries from './queries'
...
export const initializeScreen = customQueries => {
const queries = {...defaultQueries, ...customQueries}
return typeof document !== 'undefined' && document.body
? getQueriesForElement(document.body, queries, {debug})
: Object.keys(queries).reduce(
(helpers, key) => {
helpers[key] = () => {
throw new TypeError(
'For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error',
)
}
return helpers
},
{debug},
)
}
export const screen = initializeScreen()Teachability, Documentation, Adoption, Migration Strategy:
- The users can import the
initializeScreenon some test-utils file they may have. - They call the function with their custom queries and obtain a new screen object that references it
- They can re-export that screen as the default one and use it on their tests.
Metadata
Metadata
Assignees
Labels
No labels