screen.getByRole('button', { name: /submit/i })getByRole('button', { name: /submit/i }) is best. It finds the element the way users and screen readers see it. It also fails if the button is not accessible.getByText('Submit') is the tempting wrong answer. It would also match text that is not a button. A CSS class like .btn-primary is an implementation detail. Test IDs are a last resort.
Read more