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

svg-jest

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-jest

A simple transformer for .SVG for Jest

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

svg-jest

This is a small library which transforms .SVG files for jest. It produces and SVG in the stream.

The transformed item will have the following properties on it.

  • data-jest-file-name: The name of the file (e.g. 'some-image.svg')
  • data-jest-svg-name: Only the name portion of the file (e.g. 'some-image')
  • data-testid: Same as data-jest-svg-name, but works with @testing-library/react getByTestId()

Works with both of these formats:

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

import { ReactComponent as MySvg}  from '../images/an-image.svg';

The following JavaScript

const MyComponent = () => {
  return (
    <div>
	<MySvg/>
    </div>
  );
}

The resulting snapshot:

<div>
    <AnImage/>
</div>

The resulting HTML:

<div>
 <svg data-jest-file-name='an-image.svg' data-jest-svg-name='an-image' data-testid='an-image'/>
</div>

In additoin, any properties passed to '' are passed along into both the snapshot and the resulting trees.

usage

Configure jest:

{
    "jest": {
        "transform": {
            "\\.svg$": "svg-jest"
        }
    }
}

Keywords

FAQs

Package last updated on 15 Jul 2020

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