Open colindresj opened 9 years ago
+1
Is this still maintained? Any alternatives?
I went with karma mocha chai and stubbed the methods manually
I have a problem stubbing the mixing. Could you give me a sample of how you did that as a reference?
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;
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
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