Skip to content

Community Middleware

Nick Stefan edited this page Oct 8, 2015 · 11 revisions
  1. TestMethod

Setting up your legit tests to always use certain middleware is easy:

import TestUtils from 'legit-tests/no-dom';
import _ from 'lodash-compat';

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);
}
Clone this wiki locally