With jest-puppeteer
– and its included expect-puppeteer
assertion library – it’s possible to use Puppeteer within your Jest tests.
Writing integration test can be done using Puppeteer API but it can be complicated and hard because API is not designed for testing.
To make it simpler, an
expectPage()
is automatically installed and available, it provides a lot of convenient methods, all documented inexpect-puppeteer
API.
describe('Google', () => {
beforeAll(async () => {
await page.goto('https://google.com')
})
it('should display "google" text on page', async () => {
expectPage().toMatch('google')
})
});
With expect-puppeteer
it’s also easy peasy to click buttons, complete forms, etc.
// Assert that a form will be filled
await expectPage().toFillForm('form[name="myForm"]', {
firstName: 'James',
lastName: 'Bond',
})