Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still maintained? #8

Open
colindresj opened this issue Apr 16, 2015 · 6 comments
Open

Still maintained? #8

colindresj opened this issue Apr 16, 2015 · 6 comments

Comments

@colindresj
Copy link

Just wanted to check in to see if this library is still being maintained. I'd like to reliably use it, but notice there's a long standing open PR. Would be happy to help out if that's needed

@jpiv
Copy link

jpiv commented Sep 9, 2015

+1

@varunshah1106
Copy link

Is this still maintained? Any alternatives?

@jpiv
Copy link

jpiv commented Oct 29, 2015

I went with karma mocha chai and stubbed the methods manually

@varunshah1106
Copy link

I have a problem stubbing the mixing. Could you give me a sample of how you did that as a reference?

@jpiv
Copy link

jpiv commented Oct 29, 2015

const TestUtils = require('react/lib/ReactTestUtils');
const React = require('react');

const ReactMethodStub = {
    _context: this,

    _spyOn: function (componentClass, method) {
        const classFunction = componentClass.prototype[method];
        delete componentClass.prototype[method]
        componentClass.prototype[method] = sinon.spy(function () {
            classFunction.apply(ReactMethodStub._context, arguments);
        });
        return componentClass.prototype[method];
    },

    stubComponent: function (componentClass, methods, props) {
        if(Array.isArray(methods)) {
            methods.forEach(function (method) {
                this._spyOn(componentClass, method);
            }, this);
        } else {
            this._spyOn(componentClass, methods);
        }
        const StubbedComponent = TestUtils.renderIntoDocument(React.createElement(componentClass, props));
        this._context = StubbedComponent;
        return StubbedComponent;
    }
};

module.exports = ReactMethodStub;

@jpiv
Copy link

jpiv commented Oct 29, 2015

I basically go through the methods on the component and replace all the methods specified with Sinon spy wrapped function. I then render the component using TestUtils and send it back so if you were to invoke a method on the stubbed component via calling it or stimulating a DOM event you have access to all the useful sinon spy properties i.e. callCount, called, calledOnce ... ext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants