Skip to content

Commit 909b2ba

Browse files
author
dphaener
committed
Add wait function for async testing
1 parent 80da711 commit 909b2ba

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "legit-tests",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "a chainable testing library for React",
55
"main": "legit-tests.js",
66
"scripts": {

src/alt/store.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ class TestStore {
66
this.actions = actions
77
}
88

9+
wait(callback, duration = 0) {
10+
setTimeout(() => {
11+
callback.call(this, this.store)
12+
}, duration)
13+
14+
return this
15+
}
16+
917
test(callback) {
1018
callback.call(this, this.store)
1119
return this

tests/store.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ describe('TestStore', () => {
4040
})
4141
})
4242
})
43+
44+
describe('wait', () => {
45+
it('should wait for the method to finish before running tests', (done) => {
46+
TestStore(MyStore, MyActions)
47+
.setInitialState({ todos: todos })
48+
.addTodo({ title: "Get Beer", complete: false })
49+
.wait(({ state }) => {
50+
expect(state.todos).to.eql(expected)
51+
done()
52+
}, 100)
53+
})
54+
})
4355
})

0 commit comments

Comments
 (0)