Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-transformer-svg

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-transformer-svg

a jest transformer for testing with svg files in react

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jest-transformer-svg

Transform svg files for for jest+react to de-clutter snapshots.

NOTE: cloned from jest-svg-transformer since it looks unmaintained, and it doesn't support Jest versions >= 27.

the latest version supports jest 28 - please use v1 for jest 27

Very useful with react-svg-loader. This allows you to import svgs directly into your react components, but still have nice snapshots.

Using enzyme's shallow rendering, for example:

import React from 'react';
import MySvg from '../images/an-image.svg';

function MyComponent() {
  return (
    <div>
      <MySvg style={{ color: 'blue' }} />
    </div>
  );
}

will result in a snapshot that looks like this:

<div>
    <SvgAnImage style={{color: 'blue'}} />
</div>

usage

This works with both enzyme and react-test-renderer.

Configure jest:

{
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest",
      "^.+\\.svg$": "jest-transformer-svg"
    }
  }
}

Keywords

FAQs

Package last updated on 25 Dec 2023

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