Skip to content

Instantly share code, notes, and snippets.

@iGitScor
Created February 22, 2019 10:57
Show Gist options
  • Save iGitScor/9a9aed338de93e8caca9723a4754fe61 to your computer and use it in GitHub Desktop.
Save iGitScor/9a9aed338de93e8caca9723a4754fe61 to your computer and use it in GitHub Desktop.
Snapshot
const puppeteer = require('puppeteer');
function pages(page) {
return 'http://localhost:8100/#/' + page;
}
describe('Relayed', () => {
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch();
});
beforeEach(async () => {
page = await browser.newPage();
await page.setViewport({ isMobile: true, hasTouch: true, height: 640, width: 320 });
});
it('Login', async () => {
await page.goto(pages('login'));
let image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
/* Focus */
const emailInput = await page.$('[formcontrolname=email] input');
await emailInput.type('dev@you2you.fr');
await emailInput.focus();
image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
/* Error */
const passwordInput = await page.$('[formcontrolname=password] input');
await passwordInput.type('123');
const form = await page.$('[type=submit]');
await form.click();
image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
});
it('Dashboard', async () => {
await page.goto(pages('dashboard'));
const image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
});
afterAll(async () => {
await browser.close();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment