3

Is there any way to get custom queries using within? Custom queries works fine for render function using adapter module:

import { render, queries } from '@testing-library/react';

import * as customQueries from './custom-queries';

const customRender = (ui, options) =>
  render(ui, { queries: { ...queries, ...customQueries }, ...options });

// re-export everything
export * from '@testing-library/react';

// override render method
export { customRender as render };

But when I use within, it doesn't see my custom query, which in general would be expected. Is there any way how within can be extended with custom query?

1 Answer 1

3

Just as you have a customRender, you can have a customWithin:

const customWithin = (element) => within(element, { ...queries,...customQueries });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.