Socket
Socket
Sign inDemoInstall

jest-image-snapshot

Package Overview
Dependencies
Maintainers
5
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-image-snapshot

Jest matcher for image comparisons. Most commonly used for visual regression testing.


Version published
Weekly downloads
391K
decreased by-22.58%
Maintainers
5
Weekly downloads
 
Created

What is jest-image-snapshot?

jest-image-snapshot is a Jest matcher for image comparisons. It allows you to write tests that compare images to a baseline image, making it useful for visual regression testing.

What are jest-image-snapshot's main functionalities?

Basic Image Comparison

This feature allows you to compare an image to a stored snapshot. If the images do not match, the test will fail.

const { toMatchImageSnapshot } = require('jest-image-snapshot');

test('compares image to snapshot', () => {
  const image = fs.readFileSync('path/to/image.png');
  expect(image).toMatchImageSnapshot();
});

Custom Configuration

This feature allows you to customize the image comparison settings, such as the threshold for differences and whether to use colors in the diff output.

const { toMatchImageSnapshot } = require('jest-image-snapshot');

expect.extend({ toMatchImageSnapshot });

test('compares image with custom config', () => {
  const image = fs.readFileSync('path/to/image.png');
  expect(image).toMatchImageSnapshot({
    customDiffConfig: { threshold: 0.1 },
    noColors: true,
  });
});

Update Snapshots

This feature allows you to update the stored snapshot with a new image. This is useful when the baseline image needs to be updated.

const { toMatchImageSnapshot } = require('jest-image-snapshot');

test('updates image snapshot', () => {
  const image = fs.readFileSync('path/to/image.png');
  expect(image).toMatchImageSnapshot({ updateSnapshot: true });
});

Other packages similar to jest-image-snapshot

Keywords

FAQs

Package last updated on 02 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc