await expect(page).toClick('button', { text: 'Home' }) makes no sense.
what you are trying to do is the action of clicking the Home button.
there is assertion hidden in this, maybe, but it should be separated from the action of clicking:
await expect(page).has('button', { text: 'Home' })
await page.click('button')
I understand your concern, but we can expect from page to click on a button, if the button is not found the assertion will not be good. It is just a shortcut for a contain + click.
It's a opinionated choice but you are still free to use or create your own matchers (or just use Raw Puppeteer API).
@Pyrolistical I agree. An alternative solution is to import the toClick() utility function directly without having to extend the jest expect API.
In your example await page.click('button') will fail if button is not in the page, so you implicitely expect it to be in the page. If I follow your thinking, this API should not return an error if button does not exist. So it is also a problem in Puppeteer API but in reality, every one expect this behaviour.
puppeteer api is not forcing you to do this. you need to separate the problem of "assert button exists" with "click button that I know exists"
Feel free to do it if you want:
await expect(page).toMatchElement('button')
await page.click('button')
As I said, this API is opinionated and as dry as possible. Integration tests are usually dense and complicated, so I prefer to avoid writing additional lines of code.
integration tests are usually dense and complicated
that's a self fulfilling statement
Most helpful comment
Feel free to do it if you want:
As I said, this API is opinionated and as dry as possible. Integration tests are usually dense and complicated, so I prefer to avoid writing additional lines of code.