-
Notifications
You must be signed in to change notification settings - Fork 7
Bundled Middleware
Zach Silveira edited this page Sep 16, 2015
·
11 revisions
Importing bundled middleware is easy:
import {Find} from 'legit-tests/middleware'
###Find Finds dom nodes and adds them to the helpers array
-
.use(Find, 'div')
finds all divs -
.use(Find, '.test')
finds all elements with the class test -
.use(Find, MyComponent)
finds all React Components of that class
Inside the test method it is accessible via this.helpers.elements.tagName
.use(Find, 'div')
.test(function() {
this.helpers.elements.div //array of divs, or a single element if there's only one
this.helpers.elements.mycomponent //lowercases component names
})
###SetState changes the component's state
.use(SetState, {test: 'changed!'})
.test(function() {
expect(this.component.state.test).to.be.equal('changed!')
})
###Simulate Simulates events on elements
arguments Object
method
- Simulate
method to be called
element
- element name from this.helpers.elements
options
- options to be passed to Simulate
method
example
let spy = sinon.spy();
Test(<TestComponent onClick={spy}/>)
.use(Find, 'button')
.use(Simulate, {method: 'click', element: 'button'})
.test(function() {
expect(spy.called).to.be.true;
})