diff --git a/index.js b/index.js index 77e7418..5e66996 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/readme.md b/readme.md index 0e4fa08..e95525d 100644 --- a/readme.md +++ b/readme.md @@ -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 }, diff --git a/test.js b/test.js index cd3c8f7..0711aa5 100644 --- a/test.js +++ b/test.js @@ -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); +});