From 909b2bac56f4108fddb6c781632397d353ff7ab2 Mon Sep 17 00:00:00 2001 From: dphaener Date: Tue, 27 Oct 2015 14:26:05 -0700 Subject: [PATCH] Add wait function for async testing --- package.json | 2 +- src/alt/store.js | 8 ++++++++ tests/store.jsx | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7562bf8..c021bc3 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/alt/store.js b/src/alt/store.js index 43121be..2f2067a 100644 --- a/src/alt/store.js +++ b/src/alt/store.js @@ -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 diff --git a/tests/store.jsx b/tests/store.jsx index d50c960..c78d686 100644 --- a/tests/store.jsx +++ b/tests/store.jsx @@ -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) + }) + }) })