You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP โ†’
Socket
Book a DemoInstallSign in
Socket

jest-image-snapshot

Package Overview
Dependencies
Maintainers
5
Versions
48
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.

6.5.1
latest
Source
npmnpm
Version published
Weekly downloads
629K
-2.66%
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

test

FAQs

Package last updated on 20 May 2025

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