Skip to content

Community Middleware

Nick Stefan edited this page Jan 25, 2016 · 11 revisions
  1. TestMethod

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

importTestUtilsfrom'legit-tests/no-dom';import{TestMethod}from'../custom/middleware';functionTest(component,options={}){returnTestUtils(component,options).mixin({
TestMethod
});}exportdefaultTest;export{Test};

###TestMethod Call and test React methods

  • .testMethod(ComponentThing, 'myMethod', function(myMethod){ ... })
  • .testMethod(ComponentThing, 'getInitialState', function(getInitialState){ ... })

The method is passed to the callback already bound to the component instance.

// ComponentThing is a React class.testMethod(ComponentThing,'myMethod',function(myMethod){expect(myMethod()).to.be('returned value');})

src:

import_from'lodash';functiontestMethod(component,methodName,fn){varmethod=methodName;varcomponentName=component.displayName.toLowerCase();this.find(component);varcomponentInstance=this.elements[componentName];varbound=_.bind(component.prototype[methodName],componentInstance);fn(bound);}

Clone this wiki locally