0

Since it is recommended to use screen rather than getById in react testing library, I'm changing all the instances of it to screen query selectors. However, there's a certain condition I'm not able to change.

const newComponent = render(
<AppContext.Provider value={newState}>
<App />
<AppContext.Provider>,
)

const id = queryByAttribute.bind(null,'id')
const result= getById(newComponent.container,'student-details')
expect(result.textContent).toBe('Suga')

I used the Testing playground and it suggested to use getByText, but if I do screen.getByText(/Suga/i), it fails because it considers the screen that rendered initially and not the new component to which I provide different state. How can I achieve this conversion?

Note: In the App.js file, the student-detail is a div with id and className.

1 Answer 1

1
const newComponent = render(
   <AppContext.Provider value={newState}>
      <App />
   <AppContext.Provider>,
)

expect(newComponent.getByText(/suga/i)).toBeInTheDocument
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.