Skip to content

Commit

Permalink
call next setup with previous return values
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Aug 13, 2016
1 parent b03a7f1 commit 0b3b222
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function BetterThanBefore() {
var ret = [];

for (var i = 0; i < setups.length && i < n; i++) {
ret.push(setups[i]());
ret.push(setups[i](ret));
}

N = n;
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ setups([
// setup for all tests
return 8; // optionally returns something
},
() => {
(ret) => { // next setup can access the return values of all previous setups
ret
//=> [8]
// setup for all tests except for tests only need the first setup
return 42; // optionally returns something
},
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ test('return all setup return values', t => {
t.deepEqual(preparing(1), [8]);
t.deepEqual(preparing(2), [8, 42]);
});

test('fn2 can access returned value of f1', t => {
const {setups, preparing} = betterThanBefore();

const fn1 = stub().returns(8);
const fn2 = function (ret) {
t.deepEqual(ret, [8]);
};

setups([
fn1,
fn2
]);

preparing(2);
});

0 comments on commit 0b3b222

Please sign in to comment.