GithubHelp home page GithubHelp logo

Comments (8)

adriantoine avatar adriantoine commented on June 28, 2024 8

Thanks for your messages! v3.0.0 has been released, please report any bugs as soon as you find them! 😄

from enzyme-to-json.

adriantoine avatar adriantoine commented on June 28, 2024 7

That's nice, I'll arrange a release of enzyme-to-json in the evening!

from enzyme-to-json.

kirill-kruchkov avatar kirill-kruchkov commented on June 28, 2024 3

@adriantoine hello! Looks like Enzyme 3 is released: https://github.com/airbnb/enzyme/releases/tag/enzyme%403.0.0

from enzyme-to-json.

fernandopasik avatar fernandopasik commented on June 28, 2024 2

React 16 is out as well
facebook/react@5c6ef40

from enzyme-to-json.

fernandopasik avatar fernandopasik commented on June 28, 2024 2

Thanks for the hard work @adriantoine !!!

from enzyme-to-json.

adriantoine avatar adriantoine commented on June 28, 2024 1

The output mapping feature I'm working on is working in the way that you can pass a map function in the options and this function will take the JSON as only parameter and can return a modified version of this JSON object.

For example:

const shallowed = shallow(
  <div randomlyGeneratedKey={Date.now()} className="wrapper">
    <strong randomlyGeneratedKey={Date.now()}>Hello!</strong>
    <strong className="strong2">Hello 2</strong>
  </div>,
);

expect(
  shallowToJson(shallowed, {
    map: json => ({
      ...json,
      props: omit(json.props, 'randomlyGeneratedKey'),
    }),
  }),
).toMatchSnapshot();

Here map is an arrow function which will remove all props called notInSnapshot, so the snapshot would be:

<div
  className="wrapper"
>
  <strong>
    Hello!
  </strong>
  <strong
    className="strong2"
  >
    Hello 2
  </strong>
</div>

and if you want to remove all attributes:

expect(
  shallowToJson(shallowed, {
    map: json => ({
      ...json,
      props: {},
    }),
  }),
).toMatchSnapshot();

outputs:

<div>
  <strong>
    Hello!
  </strong>
  <strong>
    Hello 2
  </strong>
</div>

You can also change the children of a component, return null if you don't want a component to be in your snapshots, etc...

from enzyme-to-json.

adriantoine avatar adriantoine commented on June 28, 2024

Beta 2 has been published with most of the items from the list addressed.

from enzyme-to-json.

adriantoine avatar adriantoine commented on June 28, 2024

The map feature has now been released in v3.0.0-beta4.

from enzyme-to-json.

Related Issues (20)

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.