All Projects β†’ commercetools β†’ enzyme-extensions

commercetools / enzyme-extensions

Licence: MIT license
🎩 Enzyme extensions to test shallowly rendered enzyme wrappers πŸ„πŸ»

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to enzyme-extensions

Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (+286.67%)
Mutual labels:  enzyme, jest
2019 12
🎟 κΈ‰μ¦ν•˜λŠ” νŠΈλž˜ν”½μ—λ„ μ•ˆμ •μ μΈ μ˜ˆμ•½ μ„œλΉ„μŠ€, Atomic Pattern을 μ μš©ν•œ μž¬μ‚¬μš© κ°€λŠ₯ν•œ μ»΄ν¬λ„ŒνŠΈ, μ‹€μš©μ μΈ Testing을 주제둜 ν•˜λŠ” 이벀트 μ„œλΉ„μŠ€
Stars: ✭ 169 (+463.33%)
Mutual labels:  enzyme, jest
React Redux Bootstrap Webpack Starter
React 16.9 + Typescript + React-Router 4 + Redux + Bootstrap 4 + Hot Reload + redux-devtools-extension + Webpack 4 + styled-components STARTER
Stars: ✭ 133 (+343.33%)
Mutual labels:  enzyme, jest
React Adventure
β›° React high-ending architecture & patterns ready for use. Made for big and small projects. PWA Ready.
Stars: ✭ 62 (+106.67%)
Mutual labels:  enzyme, jest
react-jest-enzyme-example
A minimal configuration for testing React components with Jest and Enzyme.
Stars: ✭ 23 (-23.33%)
Mutual labels:  enzyme, jest
Artemis Dev Tool
An Apollo GraphQL Query Schema Testing Tool
Stars: ✭ 66 (+120%)
Mutual labels:  enzyme, jest
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: ✭ 134 (+346.67%)
Mutual labels:  enzyme, jest
Enzyme To Json
Snapshot test your Enzyme wrappers
Stars: ✭ 954 (+3080%)
Mutual labels:  enzyme, jest
React
Extremely simple boilerplate, easiest you can find, for React application including all the necessary tools: Flow | React 16 | redux | babel 6 | webpack 3 | css-modules | jest | enzyme | express + optional: sass/scss
Stars: ✭ 244 (+713.33%)
Mutual labels:  enzyme, jest
Testing React Redux With Jest And Enzyme
React Redux Testing Template using Jest and Enzyme
Stars: ✭ 224 (+646.67%)
Mutual labels:  enzyme, jest
Testing Jest Enzyme
List of components and tests for post "React Components Testing with Jest & Enzyme"
Stars: ✭ 54 (+80%)
Mutual labels:  enzyme, jest
coconat
πŸ₯ StarterKit Builder for rocket-speed App creation on πŸš€ React 17 + πŸ“™ Redux 4 + 🚠 Router 5 + πŸ“ͺ Webpack 5 + 🎳 Babel 7 + πŸ“œ TypeScript 4 + πŸš” Linters 23 + πŸ”₯ HMR 3
Stars: ✭ 95 (+216.67%)
Mutual labels:  enzyme, jest
Push Starter
React Redux Starter with SSR πŸ€–
Stars: ✭ 43 (+43.33%)
Mutual labels:  enzyme, jest
Reactjs Crud Boilerplate
Live Demo
Stars: ✭ 83 (+176.67%)
Mutual labels:  enzyme, jest
Bs Enzyme
Bucklescript bindings for Enzyme
Stars: ✭ 35 (+16.67%)
Mutual labels:  enzyme, jest
React Test Demo
React test demo with Jest and Enzyme
Stars: ✭ 134 (+346.67%)
Mutual labels:  enzyme, jest
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (+2836.67%)
Mutual labels:  enzyme, jest
React Ssr Starter
All have been introduced React environment
Stars: ✭ 20 (-33.33%)
Mutual labels:  enzyme, jest
Awesome Learning
Awesome Learning - Learn JavaScript and Front-End Fundamentals at your own pace
Stars: ✭ 216 (+620%)
Mutual labels:  enzyme, jest
React-Redux-Enterprise
A React-Redux boilerplate for enterprise/large scaled web applications
Stars: ✭ 77 (+156.67%)
Mutual labels:  enzyme, jest

commercetools logo @commercetools/enzyme-extensions

Logo

CircleCI Status Codecov Coverage Status Downloads per Week Made with Coffee

Why should you use this? Read: Test a Render Prop!

NOTE This package used to provide a renderProp test helper, which is now part of enzyme itself as of v3.8.0 🎈.

We therefore dropped renderProp in v4.0.0 of this package. We recommend to use renderProp from enzyme itself instead.

Be aware that the API has changed while moving the function to enzyme.

// before
wrapper.renderProp('foo', 10, 20);
// after
wrapper.renderProp('foo')(10, 20);

party-parrot We are happy that our little helper has made it into enzyme.

What assumptions is this built with?

  • We like to shallow render and avoid mounting
    • 🀺 Shallow rendering is fast and ensures that you only interact with the unit under test
    • πŸ™ Shallow rendering ensures that you do not snapshot past your test's concern
    • 🏎 Shallow rendering has shown to be more performant for us than mounting
  • We like declarative components and Render Props
    • 🧠 We can compose components easily while following along their interactions
    • πŸ”ͺ We like stubbing to test individual pieces of logic

Installation

1. Add package

yarn add @commercetools/enzyme-extensions -D

2. Add a test setup file (test runner dependent)

For Jest you would set up a setupTestFrameworkScriptFile. Create that file and add it to the jest configuration.

3. Extend Enzyme with this package's helpers

In that testFrameworkScriptFile file, import the extensions and add them to Enzyme

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-xx';
import configure from '@commercetools/enzyme-extensions';
import ShallowWrapper from 'enzyme/ShallowWrapper';

// You likely had this part already
Enzyme.configure({ adapter: new Adapter() });

// This is the actual integration.
// Behind the scenes this extends the prototype of the passed in `ShallowWrapper`
configure(ShallowWrapper);

Usage

Once set up, you can use the extension in your test files like this:

import React from 'react';
import { shallow } from 'enzyme';

describe('when rendering `<App>`', () => {
  const App = () => (
    <div id="app">
      <Mouse
        render={(x, y) => (
          <div>
            Cursor is at {x} {y}
          </div>
        )}
      />
    </div>
  );

  // Here we call the render function defined on Mouse and we provide
  // some custom arguments to it. This means we are effectively mocking
  // the Mouse component's implementation.
  // This is great to keep test concerns separate.
  const wrapper = shallow(<App />)
    .find(Mouse)
    // This is where we are actually using the drill function
    // Since we defined it on the prototype in the Installation step,
    // it does not need to be imported into the test itself.
    // We can call any property dynamically and even derive the property to
    // call depending on the props which are passed as the arguments of the
    // function passed to `drill`.
    .drill(props => props.render(10, 20));

  it('should render the mouse position', () => {
    expect(wrapper.equals(<div>Cursor is at 10 20</div>)).toBe(true);
  });
});

Enzyme's renderProp is built as an easy to use test helper for the most common cases. In case you need more control, you can use drill instead. drill offers more flexibility as:

  • the prop-to-call can be derived from the other props
  • the returned element can be set dynamically

See the drill documentation for more.

Documentation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].