UNPKG

877 BJavaScriptView Raw
1import { toMatchImageSnapshot } from 'jest-image-snapshot';
2import { defaultImageSnapshotConfig } from './config';
3import { puppeteerTest } from './puppeteerTest';
4expect.extend({ toMatchImageSnapshot });
5export const imageSnapshot = (customConfig = {}) => {
6 const config = { ...defaultImageSnapshotConfig, ...customConfig };
7 const { getMatchOptions, getScreenshotOptions, beforeScreenshot, afterScreenshot } = config;
8 return puppeteerTest({
9 ...config,
10 async testBody(page, options) {
11 expect.hasAssertions();
12 const element = await beforeScreenshot(page, options);
13 const image = await (element || page).screenshot(getScreenshotOptions(options));
14 await afterScreenshot({ image, context: options.context });
15 expect(image).toMatchImageSnapshot(getMatchOptions(options));
16 },
17 });
18};