kentcdodds / jest-glamor-react

Jest utilities for Glamor and React
https://npm.im/jest-glamor-react
MIT License
98 stars 24 forks source link

feat(serializer): support providing a custom StyleSheet instance #10

Closed emmatown closed 7 years ago

emmatown commented 7 years ago

What:

Let people pass in a custom StyleSheet instance to serializer.

Why:

So that people who use css-in-js solutions like cxs can use jest-glamor-react to test their components.

How:

I wrapped the current serializer in a function that accepts a StyleSheet instance and returns a serializer. To not break the current API I called the function with glamor's styleSheet and put those properties onto the function itself so it can be used in these two ways; first with glamor, second with any other StyleSheet like it.

import { serializer } from 'jest-glamor-react'
expect.addSnapshotSerializer(serializer)
import { serializer } from 'jest-glamor-react'
expect.addSnapshotSerializer(serializer(sheet))

For the tests, I copied the ones from index.test.js and modified them to use cxs. In the README, I used cxs as an example.

Closes #5 Related: tkh44/emotion#21

codecov[bot] commented 7 years ago

Codecov Report

Merging #10 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #10   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines          92     95    +3     
  Branches       17     17           
=====================================
+ Hits           92     95    +3
Impacted Files Coverage Δ
src/serializer.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c251b1e...74d00aa. Read the comment docs.