From d997f3a7b634a642fe9f5bb26fa3065f74d55c06 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 26 Jan 2018 13:59:11 -0800 Subject: [PATCH] fix: allow do to modify context --- src/types.ts | 2 +- test/{run.test.ts => do.test.ts} | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) rename test/{run.test.ts => do.test.ts} (68%) diff --git a/src/types.ts b/src/types.ts index 228235b..8450336 100644 --- a/src/types.ts +++ b/src/types.ts @@ -35,7 +35,7 @@ export type Base = { (cb?: (context: I) => any): void } add(key: K, cb: (context: I) => Promise | O): Base - do(cb: (context: I) => any): Base + do(cb: (context: I & O) => any): Base register(key: K, plugin: (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin): Base } & {[P in keyof T]: (arg1?: T[P]['a1'], arg2?: T[P]['a2'], arg3?: T[P]['a3'], arg4?: T[P]['a4']) => Base} diff --git a/test/run.test.ts b/test/do.test.ts similarity index 68% rename from test/run.test.ts rename to test/do.test.ts index 8f7f34e..b534a14 100644 --- a/test/run.test.ts +++ b/test/do.test.ts @@ -2,7 +2,7 @@ import {expect, fancy} from '../src' -describe('run', () => { +describe('do', () => { fancy .stdout() .do(() => console.log('foo')) @@ -10,6 +10,13 @@ describe('run', () => { .end('runs this callback last', () => { // test code }) + + fancy + .stdout() + .do((ctx: {n: number}) => {ctx.n = 101}) + .do(ctx => console.log(ctx.n)) + .do(ctx => expect(ctx.stdout).to.equal('101\n')) + .end('runs this callback last') }) describe('add', () => {