Giter VIP home page Giter VIP logo

jest-fela-react's Introduction

jest-fela-react

Jest snapshots are amazing, but with fela, you'll get pretty ugly snapshots with classNames that don't have any meaning. However, by adding jest-fela-react to Jest, you can get snapshots diffs where you can understand the changed content.

Before

If you use fela as your CSS-in-JS solution, and you use [snapshot testing][snapshot] with [jest][jest] then you probably have some test snapshots that look like:

<div
  className="fovk07z"
>
  <div
    className="f16lnj6g"
  >
    Hello World
  </div>
</div>

After

.fovk07z> div {
  font-weight: 500;
}

.fovk07z {
  border: solid 1px black;
}

.f16lnj6g {
  color: red;
  font-size: 16px;
}

<div
  className="fovk07z"
>
  <div
    className="f16lnj6g"
  >
    Hello World
  </div>
</div>

Kent C. Dodds published jest-glamor-react, which does the same thing as jest-fela-react, but for glamor. He himself took inspiration from Michele Bertoli who worked on jest-styled-components, an equivalent for styled-component. Most of the code in this repo is actually taken from these two projects, since there is little difference between snapshotting for fela and for these other css in js solution. And because they are much better than I am, so they did a better job than I would have! All I did was make it compatible with fela.

Updated diff

Installation

yarn -D jest-glamor-react

Usage

At the top of your test file:

import createSerializer from 'jest-fela-react'
import {createRenderer} from 'fela';
import monolithic from 'fela-monolithic';

const felaRenderer = createRenderer({
    enhancers: [monolithic()]
})

expect.addSnapshotSerializer(createSerializer(felaRenderer))

// You're free to write your tests as you wish

Using fela-monolithic is not necessary, however, if you skip this part, you'll end up with one class for each property, which I think is less optimal when simply looking for differences between styles.

LICENSE

MIT

jest-fela-react's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jest-fela-react's Issues

No CSS snapshotted

Is this package supposed to already work fine?
I've tried to use it locally and set up just as the README points, but I don't get anything added to my snapshots.

I am trying with [email protected] (without fela-monolithic)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.