jasmine-react icon indicating copy to clipboard operation
jasmine-react copied to clipboard

Still maintained?

Open colindresj opened this issue 9 years ago • 6 comments

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

colindresj avatar Apr 16 '15 19:04 colindresj

+1

jpiv avatar Sep 09 '15 15:09 jpiv

Is this still maintained? Any alternatives?

varunshah1106 avatar Oct 27 '15 19:10 varunshah1106

I went with karma mocha chai and stubbed the methods manually

jpiv avatar Oct 29 '15 03:10 jpiv

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

varunshah1106 avatar Oct 29 '15 04:10 varunshah1106

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 avatar Oct 29 '15 16:10 jpiv

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

jpiv avatar Oct 29 '15 16:10 jpiv