-
Notifications
You must be signed in to change notification settings - Fork 7
Community Middleware
Nick Stefan edited this page Oct 10, 2015
·
11 revisions
Setting up your legit tests to always use certain middleware is easy:
import TestUtils from 'legit-tests/no-dom';
import {TestMethod} from '../custom/middleware';
function Test(component, options={}){
return TestUtils(component, options)
.mixin({
TestMethod
});
}
export default Test;
export { Test };
###TestMethod Call and test React methods
.testMethod('myMethod', function(myMethod){ ... })
.testMethod('getInitialState', function(getInitialState){ ... })
The method is passed to the callback already bound to the component instance.
.testMethod('myMethod', function(myMethod){
expect( myMethod() ).to.be('returned value');
})
src:
import _ from 'lodash';
function TestMethod(methodName, fn){
var bound = _.bind(this.component.type.prototype[methodName], this.component);
fn(bound);
}