Code Monkey home page Code Monkey logo

jest-glamor-react's Introduction

jest-glamor-react

Jest utilities for Glamor and React

Build Status Code Coverage version downloads MIT License

All Contributors PRs Welcome Donate Code of Conduct Roadmap Examples

Watch on GitHub Star on GitHub Tweet

Sponsor

The problem

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

<h1
  class="css-1tnuino"
>
  Hello World
</h1>

And that's not super helpful from a styling perspective. Especially when there are changes to the class, you can see that it changed, but you have to look through the code to know what caused the class name to change.

This solution

This allows your snapshots to look more like:

.css-0,
[data-css-0] {
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
}

<h1
  class="css-0"
>
  Hello World
</h1>

This is much more helpful because now you can see the CSS applied and over time it becomes even more helpful to see how that changes over time.

This builds on the work from @MicheleBertoli in jest-styled-components to bring a similar experience to React projects that use glamor.

Table of Contents

Preview

Terminal Screenshot

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev jest-glamor-react

Usage

At the top of your test file:

import serializer from 'jest-glamor-react'

expect.addSnapshotSerializer(serializer)

Or in your Jest serializer config:

{
  "snapshotSerializers": [
    "jest-glamor-react"
  ]
}

If you have set jest.config variable "testEnvironment": "node", you will need to manually mock up browser gloabl objects so it is recommended to use "testEnvironment": "jsdom" instead.

Here are some components:

import React from 'react'
import * as glamor from 'glamor'

function Wrapper(props) {
  const className = glamor.css({
    padding: '4em',
    background: 'papayawhip',
  })
  return <section className={`${className}`} {...props} />
}

function Title(props) {
  const className = glamor.css({
    fontSize: '1.5em',
    textAlign: 'center',
    color: 'palevioletred',
  })
  return <h1 className={`${className}`} {...props} />
}

Here's how we'd test them with ReactDOM.render:

import React from 'react'
import ReactDOM from 'react-dom'

function render(ui) {
  const div = document.createElement('div')
  ReactDOM.render(ui, div)
  return div.children[0]
}

test('react-dom', () => {
  const node = render(
    <Wrapper>
      <Title>Hello World, this is my first glamor styled component!</Title>
    </Wrapper>,
  )
  expect(node).toMatchSnapshot()
})

And here's how we'd test them with react-test-renderer:

import React from 'react'
import renderer from 'react-test-renderer'

test('react-test-renderer', () => {
  const tree = renderer
    .create(
      <Wrapper>
        <Title>Hello World, this is my first glamor styled component!</Title>
      </Wrapper>,
    )
    .toJSON()

  expect(tree).toMatchSnapshot()
})

Works with enzyme too:

import * as enzyme from 'enzyme'
import toJson from 'enzyme-to-json'

test('enzyme', () => {
  const ui = (
    <Wrapper>
      <Title>Hello World, this is my first glamor styled component!</Title>
    </Wrapper>
  )

  expect(toJson(enzyme.shallow(ui))).toMatchSnapshot(`enzyme.shallow`)
  expect(toJson(enzyme.mount(ui))).toMatchSnapshot(`enzyme.mount`)
  expect(toJson(enzyme.render(ui))).toMatchSnapshot(`enzyme.render`)
})

Custom matchers

toHaveStyleRule(property, value)

expect(node).toHaveStyleRule(property: string, value: string | RegExp)

Installation:

import serializer, {toHaveStyleRule} from 'jest-glamor-react'
expect.addSnapshotSerializer(serializer)
expect.extend({toHaveStyleRule})

Usage:

If we use the same examples as those above:

import React from 'react'
import ReactDOM from 'react-dom'

function render(ui) {
  const div = document.createElement('div')
  ReactDOM.render(ui, div)
  return div.children[0]
}

test('react-dom', () => {
  const node = render(
    <Wrapper>
      <Title>Hello World, this is my first glamor styled component!</Title>
    </Wrapper>,
  )
  expect(node).toHaveStyleRule('background', 'papayawhip')
})

Or with react-test-renderer:

import React from 'react'
import renderer from 'react-test-renderer'

test('react-test-renderer', () => {
  const tree = renderer
    .create(
      <Wrapper>
        <Title>Hello World, this is my first glamor styled component!</Title>
      </Wrapper>,
    )
    .toJSON()

  expect(tree).toHaveStyleRule('background', 'papayawhip')
})

Or using Enzyme:

import {mount} from 'enzyme'

test('enzyme', () => {
  const wrapper = mount(
    <Wrapper>
      <Title>Hello World, this is my first glamor styled component!</Title>
    </Wrapper>,
  )

  expect(wrapper).toHaveStyleRule('background', 'papayawhip')
  expect(wrapper.find(Title)).toHaveStyleRule('color', 'palevioletred')
})

Integration with snapshot-diff

snapshot-diff is this really neat project that can help you get more value out of your snapshots. As far as I know, this is the best example of how to integrate this serializer with that handy matcher:

import React from 'react'
import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import * as glamor from 'glamor'
import {toMatchDiffSnapshot, getSnapshotDiffSerializer} from 'snapshot-diff'
import serializer, {fromDOMNode} from 'jest-glamor-react'

expect.addSnapshotSerializer(getSnapshotDiffSerializer())
expect.addSnapshotSerializer(serializer)
expect.extend({toMatchDiffSnapshot})

function Button({count, ...props}) {
  const className = glamor.css({margin: 10 + count})
  return <button className={`${className}`} {...props} />
}

class Counter extends React.Component {
  state = {count: 0}
  increment = () => {
    this.setState(({count}) => ({count: count + 1}))
  }
  render() {
    const {count} = this.state
    return (
      <Button onClick={this.increment} count={count}>
        {count}
      </Button>
    )
  }
}

test('snapshot diff works', () => {
  const control = render(<Counter />)
  const variable = render(<Counter />)
  Simulate.click(variable)
  expect(fromDOMNode(control)).toMatchDiffSnapshot(fromDOMNode(variable))
})

function render(ui) {
  const div = document.createElement('div')
  ReactDOM.render(ui, div)
  return div.children[0]
}

The result of this snapshot is:

Snapshot Diff:
- First value
+ Second value

  .css-0,
  [data-css-0] {
-   margin: 10px;
+   margin: 11px;
  }

- <button class="css-0">0</button>
+ <button class="css-0">1</button>

Pretty handy right?!

Notice the fromHTMLString function you can import from jest-glamor-react. That's what jest-glamor-react uses internally if you try to snapshot a string that looks like HTML and includes css- in it. I can't think of any other context where it would be useful, so it's not documented beyond this example.

Inspiration

As mentioned earlier, @MicheleBertoli's jest-styled-components was a huge inspiration for this project. And much of the original code came from from that MIT Licensed project. Thank you so much Michele! ๐Ÿ‘

Other Solutions

I'm unaware of other solutions. Please file a PR if you know of any!

Contributors

Thanks goes to these people (emoji key):


Michele Bertoli

๐Ÿ’ป ๐Ÿ“– โš ๏ธ

Kent C. Dodds

๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ โš ๏ธ

Mitchell Hamilton

๐Ÿ’ป ๐Ÿ“– โš ๏ธ

jhurley23

๐Ÿ’ป โš ๏ธ ๐Ÿ“–

Gaurav Talwar


Henry Lewis

๐Ÿ› ๐Ÿ’ป

Alexey Svetliakov

๐Ÿ’ป โš ๏ธ

James W Lane

๐Ÿ› ๐Ÿ’ป โš ๏ธ

Brent Ertz

๐Ÿ“–

Junyoung Clare Jang

๐Ÿ’ป โš ๏ธ

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

jest-glamor-react's People

Contributors

ailrun avatar asvetliakov avatar bcbrian avatar danreeves avatar emmatown avatar hjylewis avatar jameswlane avatar megaurav2002 avatar michelebertoli avatar yamafaktory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jest-glamor-react's Issues

Is there any ways to get style for pseudo-class?

  • jest-glamor-react version: v4.2.1
  • node version: v8.9.4
  • npm (or yarn) version: v5.6.0

Relevant code or config

const TestComp = glamorous.div({
  '::after': {
    backgroundColor: 'white',
  },
});

it('should have white background', () => {
  const component = enzyme.shallow(<TestComp />);
  expect(component).toHaveStyleRule(/* What should I do ??? */);
});

What you did:
Try to test pseudo-class style

What happened:
No way to test it

Problem description:

Suggested solution:
Add some matchers? or add functions to the matcher?

css- prefixed selectors are not replaced if the component has no styles

  • jest-glamor-react version: 3.2.2
  • node version: 8.9.0
  • npm (or yarn) version: yarn 1.3.2

Relevant code or config

I created a repo that demonstrates the problem.

If a component that has selectors prefixed with css- but the component does not have any styles associated with those selectors, the selectors will not be replaced in the snapshot. I realize this sounds weird, but Emotion will add selectors like this when using its styled utility and the babel-plugin-emotion.

You can see a contrived example here. Note that as long as at least one selector has styles associated with it, all of the css- prefixed selectors get replaced. It's only when none of the selectors are in the stylesheet that it doesn't rewrite them.

Here is an example with Emotion.

Suggested Fix:
I'm going to submit a PR shortly.

`snapshotSerializers` failing on CI

  • jest-glamor-react version: 3.1.0
  • node version: 8.1.2
  • npm (or yarn) version: 0.24.6

Relevant code or config:

{
    "snapshotSerializers": [
      "jest-glamor-react"
    ]
}

What you did:

Code was working as expected, then after updating the following packages:

{
  "@storybook/addon-actions": "^3.2.10",
  "@storybook/addon-links": "^3.2.10",
  "@storybook/addon-options": "^3.2.10",
  "@storybook/addons": "^3.2.10",
  "@storybook/react": "^3.2.10"
}

to

{
  "@storybook/addon-actions": "^3.2.10",
  "@storybook/addon-links": "^3.2.10",
  "@storybook/addon-options": "^3.2.10",
  "@storybook/addons": "^3.2.10",
  "@storybook/react": "^3.2.10"
}

What happened:

Appears to be non-functional

-      className="glamor-0"
+      className="css-1139u7f"

Problem description:

In an attempt to diagnose, I cloned a fork locally and when linking via yarn I can reproduce the issue. If I link via npm the issue goes away.

Suggested solution:

I assume this has something to do with the way that yarn makes this lib is made available to jest as a custom serializer.

Sort CSS output?

Otherwise, it appears that it's kinda random and the diffs are really weird. If they could be sorted then maybe they'd stay in the same place? It's unclear. I think that this could help with that though...

Locally linked repos do not have their components styles transformed

  • jest-glamor-react version: 4.3.1
  • node version: 9.11.2
  • npm (or yarn) version: 6.1.0

What you did:
I have two repositories, one that contains a UI library using glamour and the other that contains our production site, also using glamor. Both are using the same version of jest-glamor-react. In our main repo, when we have the UI library installed normally, we see the styles come through on all components, and all is well. But when running npm link to symlink to a local copy of the UI library, components from that library no longer get transformed, and we just get data-css-hash in our snapshots for those components.

Reproduction repository:
https://github.com/chrissinclairedited/jest-glamor-react-issue-library
https://github.com/chrissinclairedited/jest-glamor-react-issue-client

Clone both and link client -> library (the dependency in client is expecting it to be called library) and the tests pass. But looking at the snapshots for the client, the test that depends on the library component doesn't include the styles.

Problem description:
Snapshots are not transforming css classes when the component exists in a locally linked repo.

Suggested solution:
Treat locally linked libraries the same way as locally installed ones and transform the styles on that repo.

Support expect matchers on value field

  • jest-glamor-react version: v4.2.1
  • node version: v8.11.1
  • npm (or yarn) version: v5.8.0

Relevant code or config

it('could accept expect matchers', () => {
  expect(component).toHaveStyleRule('position', expect.anything());
});

function valueMatches(declaration, value) {
return value instanceof RegExp
? value.test(declaration.value)
: value === declaration.value
}

Problem description:
toHaveStyleRule accepts only RegExp or String

Suggested solution:
Add https://github.com/facebook/jest/tree/master/packages/expect as a dependency and use expect to check equivalence.

P.S. Could I make a PR for this?

Jest configuration - test environment value

I was just trying out this but i was struggling to render the css styles in my snapshot. After spending a few hours, i realized i had "testEnvironment": "node" set.

Wondering if this should be a documentation update or a warning that gets shown when the tests are run. I can try to contribute with this.

Snapshot testing of DOM element clears out that elements children

  • jest-glamor-react version: 4.3.1
  • node version: 8.11.2
  • npm (or yarn) version: yarn 1.7.0

https://github.com/pbomb/null-after-snaphot

What you did:

Wrote simple component and test using react-testing-library. Asserting snapshot using:

expect(container.firstChild).toMatchSnapshot();

What happened:

After this line executes, for some reason container.firstChild becomes null. It's not null before the snapshot is compared. This causes errors to be output when running cleanup from react-testing-library after each test because React complains that the DOM node we're trying to unmount doesn't seem to have the expected children.

Reproduction repository:

https://github.com/pbomb/null-after-snaphot

Problem description:

It seems that something within jest / jsdom / jest-glamor-react is setting the DOM node to null somehow.

Suggested solution:

Not really sure, unfortunately what the root cause is. I don't really even understand how the container object's firstChild property is getting set to null.

Placeholder classnames doesn't seem to work

  • glamor version: 2.20.40
  • jest-glamor-react version: 3.2.1
  • node version: 8.9.1
  • yarn version: 1.3.2

What happened:
When running snapshot testing the classnames are not being replaced with placeholder classnames.

Reproduction repository:
https://github.com/jameswlane/jest-glamor-react-issue

Problem description:
My snapshots are using glamor classnames

exports[`<LineScaleRandom> <LineScaleRandom> Mount 1`] = `
<LineScaleRandom
  loading={true}
>
  <div
    className="css-1jz1ji0"
  >
    <div />
    <div />
    <div />
    <div />
  </div>
</LineScaleRandom>
`;

Inconsistent Snapshots on CI

  • jest-glamor-react version: 3.2.2
  • node version: 8.0
  • npm (or yarn) version: Yarn: 0.27.5

Relevant code or config

test('Button with Children', () => {
    const ui = <Button>Hello World</Button>;
    expect(toJson(shallow(ui))).toMatchSnapshot('enzyme.shallow');
    expect(toJson(mount(ui))).toMatchSnapshot('enzyme.mount');
    expect(toJson(render(ui))).toMatchSnapshot('enzyme.render');
  });
import { configure } from 'enzyme';
import serializer from 'jest-glamor-react';
import Adapter from 'enzyme-adapter-react-16';
import { createSerializer } from 'enzyme-to-json';

expect.addSnapshotSerializer(createSerializer({ mode: 'deep' }));
expect.addSnapshotSerializer(serializer);

configure({ adapter: new Adapter() });

What you did:
Created snapshots locally, and ran build on CircleCI

What happened:

  expect(value).toMatchSnapshot()
    
    Received value does not match stored snapshot 1.
    
    - Snapshot
    + Received
    
    @@ -23,31 +23,39 @@
        -webkit-transition: 0.25s cubic-bezier(0.17, 0.67, 0.52, 0.97);
        -moz-transition: 0.25s cubic-bezier(0.17, 0.67, 0.52, 0.97);
      }
      
      .glamor-0:hover,
    - [data-glamor-0]:hover {
    + [data-glamor-0]:hover,
    + .glamor-0[data-simulate-hover],
    + [data-glamor-0][data-simulate-hover] {
        opacity: 0.7;
        transform: translateY(-1px);
        box-shadow: 0 4px 10px rgba(0,0,0,.25);
        -webkit-transform: translateY(-1px);
      }
      
      .glamor-0:focus,
    - [data-glamor-0]:focus {
    + [data-glamor-0]:focus,
    + .glamor-0[data-simulate-focus],
    + [data-glamor-0][data-simulate-focus] {
        outline: 0;
        color: #fff;
      }
      
      .glamor-0:visited,
    - [data-glamor-0]:visited {
    + [data-glamor-0]:visited,
    + .glamor-0[data-simulate-visited],
    + [data-glamor-0][data-simulate-visited] {
        outline: 0;
        color: #fff;
      }
      
      .glamor-0:active,
    - [data-glamor-0]:active {
    + [data-glamor-0]:active,
    + .glamor-0[data-simulate-active],
    + [data-glamor-0][data-simulate-active] {
        transform: translateY(1px);
        color: #fff;
        -webkit-transform: translateY(1px);
      }
      

       8 |   test('Button with Children', () => {
       9 |     const ui = <Button>Hello World</Button>;
    > 10 |     expect(toJson(shallow(ui))).toMatchSnapshot('enzyme.shallow');
      11 |     expect(toJson(mount(ui))).toMatchSnapshot('enzyme.mount');
      12 |     expect(toJson(render(ui))).toMatchSnapshot('enzyme.render');
      13 |   });
      

Reproduction repository:

Problem description:

What seems to be happening is that on when the test run on CircleCI, it expects

     [data-glamor-0]:hover,
     .glamor-0[data-simulate-hover],
     [data-glamor-0][data-simulate-hover] 

, though when running tests locally they generate the snapshot with

 [data-glamor-0]:hover 
...

Suggested solution:
Still fuzzy on what exactly is happening

Support providing custom StyleSheet instance.

Since there are multiple libraries out there that are built on glamor, if you allow the user to pass in the instance of StyleSheet from their lib you can support them all!

If this sounds like something you would like to add I can do most of the legwork. I have already tested this with cxs to test restyles.

Use placeholder classnames

See this. Doing this could significantly improve code reviews and avoid this problem:

screen shot 2017-06-26 at 4 20 55 pm

Notice that none of those rules changed. So it's just noise in the diff. Would be much nicer to only see the diff where it changed.

Though, that could present other problems. Like what happens when I add another styled component into the mix? That would bump all of the placeholders up. Would that be all that bad though ๐Ÿค”. Perhaps @MicheleBertoli can share some thoughts

EDIT: Solved, user error. --- No styles output in snapshot

EDIT:
After creating a new example project from scratch, this library works as expected.
Sorry for the confusion, please delete/close this issue.

I've used the following package.json to get everything up and running:

{
  "name": "jest-glamor-react-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "UNLICENSED",
  "devDependencies": {
    "babel-jest": "^20.0.0",
    "babel-preset-env": "^1.4.0",
    "babel-preset-react": "^6.24.1",
    "glamor": "^2.20.25",
    "jest": "^20.0.0",
    "jest-glamor-react": "^1.3.0",
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-test-renderer": "^15.5.4"
  }
}

With the following .babelrc file:

{
	"presets": [
		["env", {
			"targets": {
				"node": 7
			}
		}],
		"react"
	]
}

I then added a file in test/Example.test.js with the contents of the example in the README.md.

Then running npm t creates the snapshot with the style rules in them as expected.

Again, thanks for this!

Should this work with babel-plugin-glamorous-displayname

  • jest-glamor-react version: 3.2.2
  • node version: 8.9.1
  • npm (or yarn) version: yarn 1.3.2

Before I work on a repro for this, I just want to know if this should work--we're using both babel-plugin-glamorous-displayname and jest-glamor-react. Our snapshots end up looking like this:

exports[`PageWrapper renders default 1`] = `
.glamor-0,
[data-glamor-0] {
.......

But I would expect them to make use of the displayName (which works in dev). Should this not work with this plugin, or should it and I may have something wrong?

Thanks!

Help setting up snapshots

Versions

  • jest-glamor-react version: 1.4.0
  • enzyme version: 2.9.1
  • enzyme-to-json version: 1.5.1
  • glamor versions:
    • 3.0.0-3 via gatsby-plugin-glamor
    • 2.20.25 via @storybook/react and jest-glamor-react
  • node version: 8.1.4
  • yarn version: 0.27.5

Configuration

// package.json
"devDependencies": {
    "babel-eslint": "^7.2.3",
    "babel-jest": "^20.0.3",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "enzyme": "^2.9.1",
    "enzyme-to-json": "^1.5.1",
    "glamor": "^3.0.0-3",
    "jest": "^20.0.4",
    "jest-environment-node-debug": "^2.0.0",
    "jest-glamor-react": "^1.4.0",
    "react-addons-test-utils": "^15.6.0",
    "react-test-renderer": "^15.6.1",
  },
"jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/testUtils/customMatchers.js",
    "testEnvironment": "jsdom",
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "transform": {
      "^.+\\.js$": "babel-jest",
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/testUtils/fileTransformer.js"
    }
  }
// <rootDir>/testUtils/customMatchers.js
import { matcher, serializer } from 'jest-glamor-react'
expect.addSnapshotSerializer(serializer)
expect.extend(matcher)

Setup

For this component:

// src/components/ProfilePicture/index.js
import React from 'react'
import { css } from 'glamor'
import picturePath from '../../assets/profile.jpg'

const ProfilePicture = ({ path = picturePath, alt = 'Profile Picture', side = 140 }) => {
  const pictureSide = `${side}px`
  const pictureStyle = css({
    width: pictureSide,
    height: pictureSide,
    borderRadius: '50%',
    borderWidth: side < 100 ? '2px' : '4px',
    borderColor: '#ffffff',
    borderStyle: 'solid'
  })

  return (
    <img {...pictureStyle} src={path} alt={alt} />
  )
}

export default ProfilePicture

With this test:

// src/components/ProfilePicture/__tests__/ProfilePicture.test.js
import React from 'react'
import * as enzyme from 'enzyme'
import toJson from 'enzyme-to-json'
import ProfilePicture from '../../ProfilePicture'

describe('<ProfilePicture />', () => {
  let wrapper

  describe('with default props', () => {
    beforeEach(() => {
      wrapper = shallow(
        <ProfilePicture />
      )
    })

    test('renders the component', () => {
      expect(toJson(wrapper)).toMatchSnapshotWithGlamor(`enzyme.shallow`)
    })
  })
})

The generated snapshot is:

// src/components/ProfilePicture/__tests__/__snapshots__/ProfilePicture.test.js.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`enzyme.shallow 1`] = `
<img
  alt="Profile Picture"
  data-css-iqk43n=""
  src="profile.jpg"
/>
`;

Problem
The generated snapshot does not contain any CSS class. I was expecting to have css-iqk43n with:

{
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border-width: 4px;
    border-color: #ffffff:
    border-style: solid;
}

Suggested solution
I don't really know, since I followed the README. The only difference is that I use glamor's {...pictureStyle} syntax and the README has className, but I tried that and it didn't work.

Thanks in advance.

Setup instructions unclear

Thanks for putting the time to release this jest module. The first step in the instructions is

At the top of your test file:

import {matcher, serializer} from '../src'
expect.addSnapshotSerializer(serializer)
expect.extend(matcher)

I feel like I'm missing something. Where do matcher and serializer come from? I'm using create-react-app in my project, if that's worth mentioning. As it is, jest complains that it "Cannot find module ../../src".

I tried this:

import {matcher, serializer} from 'jest-glamor-react';
expect.addSnapshotSerializer(serializer)
expect.extend(matcher)

And my tests started "passing" while throwing this error:

(node:10440) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Network request failed

Thanks!

Just wanted to say thanks for this package! I'm just getting into using jest to actually test what is being rendered to the DOM instead of only the logic in my applications. I didn't have the slightest idea how to do so but the with-jest example in glamorous and this package have helped me immensely! ๐Ÿ‘ ๐Ÿ’ฏ

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.