Test material-ui Button text

Viewed 1356

I have a material UI button and I want to write a test to check if it rendered with the right test. I've tried

expect(wrapper.find('.btn-class').text()).toBe('Next')

but it fails with:

Expected: "Next" 
Received: "<Button />"
2 Answers

expect(wrapper.find(".btn-class").prop("children")).toEqual("Next");

It is always better to avoid render.

This was the solution I came up with

expect(wrapper.find('.btn-class').render().text()).toBe('Next')

Related