Skip to content

Commit

Permalink
Adds test for multiple defers in a single action
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Jan 16, 2015
1 parent 8548204 commit f13c4cb
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class MyActions {
'callInternalMethod',
'shortHandBinary',
'getInstanceInside',
'dontEmit'
'dontEmit',
'moreActions2',
'moreActions3'
)
this.generateActions('anotherAction')
}
Expand All @@ -25,6 +27,12 @@ class MyActions {
}
}

moreActions() {
this.dispatch(1)
this.actions.moreActions2.defer(2)
this.actions.moreActions3.defer(3)
}

updateTwo(a, b) {
this.dispatch({ a, b })
}
Expand Down Expand Up @@ -78,6 +86,8 @@ class SecondStore {
this.name = myStore.getState().name
this.instance = null

this.deferrals = 0

this.bindActions(myActions)
}

Expand All @@ -104,6 +114,18 @@ class SecondStore {
this.instance = this.getInstance()
}

onMoreActions(x) {
this.deferrals = x
}

onMoreActions2(x) {
this.deferrals = x
}

onMoreActions3(x) {
this.deferrals = x
}

static externalMethod() {
return this.getState().foo
}
Expand Down Expand Up @@ -256,8 +278,6 @@ var lifecycleStore = alt.createStore(LifeCycleStore)
assert.equal(e.message, 'Stores have already been bootstrapped', 'can only bootstrap once')
}

// assert.equal(myStore.getState().name, 'badger', 'store state still the same')

myActions.updateTwo(4, 2)
assert.equal(secondStore.getState().foo, 6, 'im able to pass two params into an action')

Expand Down Expand Up @@ -434,4 +454,10 @@ var lifecycleStore = alt.createStore(LifeCycleStore)
} catch (e) {
assert.equal(e instanceof ReferenceError, true, 'error was thrown for store with same name')
}

myActions.moreActions()
assert.equal(secondStore.getState().deferrals, 1, 'deferrals is initially set to 1')
setTimeout(() => {
assert.equal(secondStore.getState().deferrals, 3, 'but deferrals ends up being set to 3 after all actions complete')
})
}()

0 comments on commit f13c4cb

Please sign in to comment.