-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,12 @@ | |
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "ava" | ||
}, | ||
"author": "rt2zz <[email protected]>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"ava": "^0.13.0", | ||
"redux": "^3.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import test from 'ava' | ||
|
||
import { createStore, applyMiddleware } from 'redux' | ||
import actionBuffer from '../index' | ||
|
||
const BREAKER = 'BREAKER' | ||
|
||
// @TODO split into multiple atomic tests | ||
test('buffers actions', t => { | ||
var actionHistory = [] | ||
|
||
function breakCallback(err, {results, queue}) { | ||
// result is an object with results and queue arrays | ||
t.is(results.length, 2) | ||
t.is(queue.length, 2) | ||
} | ||
|
||
let store = createStore( | ||
(state, action) => { | ||
if (action.type.indexOf('@@') !== 0) actionHistory.push(action) | ||
return {} | ||
}, | ||
null, | ||
applyMiddleware(actionBuffer(BREAKER, breakCallback)) | ||
) | ||
|
||
let action1 = {type: 'ACTION1'} | ||
let action2 = {type: 'ACTION2'} | ||
let action3 = {type: 'ACTION3'} | ||
let breaker = {type: 'BREAKER'} | ||
|
||
let r1 = store.dispatch(action1) | ||
let r2 = store.dispatch(action2) | ||
let rB = store.dispatch(breaker) | ||
let r3 = store.dispatch(action3) | ||
|
||
// buffered actions return strings, other actions return themselves | ||
t.ok(typeof r1 === 'string') | ||
t.ok(typeof r2 === 'string') | ||
t.same(rB, breaker) | ||
t.same(r3, action3) | ||
|
||
// history is re-ordered as expected | ||
t.is(actionHistory.indexOf(breaker), 0) | ||
t.is(actionHistory.indexOf(action1), 1) | ||
t.is(actionHistory.indexOf(action2), 2) | ||
t.is(actionHistory.indexOf(action3), 3) | ||
t.pass() | ||
}) |