Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
Community Middleware
Nick Stefan edited this page Jan 25, 2016
·
11 revisions
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);}