Skip to content

Commit

Permalink
Add wait function for async testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dphaener committed Oct 27, 2015
1 parent 80da711 commit 909b2ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "legit-tests",
"version": "0.5.2",
"version": "0.5.3",
"description": "a chainable testing library for React",
"main": "legit-tests.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/alt/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ class TestStore {
this.actions = actions
}

wait(callback, duration = 0) {
setTimeout(() => {
callback.call(this, this.store)
}, duration)

return this
}

test(callback) {
callback.call(this, this.store)
return this
Expand Down
12 changes: 12 additions & 0 deletions tests/store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ describe('TestStore', () => {
})
})
})

describe('wait', () => {
it('should wait for the method to finish before running tests', (done) => {
TestStore(MyStore, MyActions)
.setInitialState({ todos: todos })
.addTodo({ title: "Get Beer", complete: false })
.wait(({ state }) => {
expect(state.todos).to.eql(expected)
done()
}, 100)
})
})
})

0 comments on commit 909b2ba

Please sign in to comment.