Giter Club home page Giter Club logo

react-stateless-wrapper's Introduction

Deprecated, there are better options now, check out Enzyme

Wraps React stateless components into regular components, for unit testing purposes.

npm install react-stateless-wrapper --save-dev

Usage:

import { wrap } from 'react-stateless-wrapper'
let WrappedComponent = wrap(StatelessComponent)
TestUtils.renderIntoDocument(<WrappedComponent ...props/>)

react-stateless-wrapper's People

Contributors

choonkending avatar yoyuum avatar

Stargazers

liujian zhang avatar Elijah Manor avatar Marwan Zibaoui avatar 雷明 avatar ltchronus avatar H.Alper Tuna avatar Nick Ryall avatar Ivan Sosnin avatar vagusX avatar Daniel Norman avatar Maciej Kalisz avatar Wesley Merkel avatar Clément Oriol avatar Will McFarland avatar Pete Nykänen avatar Kier Borromeo avatar  avatar Robin Pokorny avatar Michael Zimmerman avatar  avatar afc163 avatar Cymen Vig avatar Blaine Kasten avatar Thomas L. avatar

Watchers

James Cloos avatar Mehdi Mollaverdi avatar

react-stateless-wrapper's Issues

Pass in `context` when rendering stateless components

Not sure whether this is intentional, but I reckon it would be useful to pass in context when wrapping the stateless component. Docs here.

Recently ran into this when writing a test for a stateless component that needed to accept context in the argument.

I modified this locally and it worked really well.

function wrap(statelessComponent) {
  return React.createClass({
    displayName: statelessComponent.name,
    render: function() {
      return statelessComponent(this.props, this.context);
    }
  });
}

Let me know what you think (or whether you think stubbing the context should be handled by another wrapper).

Good work with this wrapper btw!

scryRenderedDOMComponentsWithClass does not work

When attempting to use scryRenderedDOMComponentsWithClass I get the following error.

Error:

Error: Invariant Violation: findAllInRenderedTree(...): instance must be a composite component
at invariant (/var/folders/bj/mb1jw15s0c1c50rz31d94zs9rm01gx/T/181ee752ae1e4062010a981a5f769705.browserify:90686:15 <- node_modules/react/node_modules/fbjs/lib/invariant.js:39:0)
at Object.ReactTestUtils.findAllInRenderedTree (/var/folders/bj/mb1jw15s0c1c50rz31d94zs9rm01gx/T/181ee752ae1e4062010a981a5f769705.browserify:84706:90 <- node_modules/react/lib/ReactTestUtils.js:143:0)
at Object.ReactTestUtils.scryRenderedDOMComponentsWithClass (/var/folders/bj/mb1jw15s0c1c50rz31d94zs9rm01gx/T/181ee752ae1e4062010a981a5f769705.browserify:84719:27 <- node_modules/react/lib/ReactTestUtils.js:156:0)
at Object. (/var/folders/bj/mb1jw15s0c1c50rz31d94zs9rm01gx/T/181ee752ae1e4062010a981a5f769705.browserify:94543:47 <- test/VerticalBar/VerticalBar.spec.jsx:18:25)

However, falling back to wrapping it in an es6 class where the render method simply renders the component works.

class TestParent extends React.Component {
render() {
return (
<VerticalBar />
);
}
}

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.