From 195a11fbc49ecebbd5951c1bdf0dd8ea9e83f6ea Mon Sep 17 00:00:00 2001 From: Thiago Oliveira Santos Date: Sat, 14 Dec 2019 12:40:34 -0300 Subject: [PATCH] maing possible to access target in beforeEach --- build/src/strict-describe-method.d.ts | 4 ++-- build/src/strict-describe-method.js | 2 +- build/src/strict-describe-method.js.map | 2 +- src/strict-describe-method.ts | 12 ++++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build/src/strict-describe-method.d.ts b/build/src/strict-describe-method.d.ts index 0ff301d..149edc3 100644 --- a/build/src/strict-describe-method.d.ts +++ b/build/src/strict-describe-method.d.ts @@ -10,11 +10,11 @@ export declare class StaticMethodDescribeHelper { export declare class MethodDescribeHelper extends StaticMethodDescribeHelper { protected readonly bootstrap: () => Target; constructor(bootstrap: () => Target, cls: ClassOf); - createMethodDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Target, fn: (it: MethodTestFunction) => void) => void; + createMethodDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void) => void; createDescribe(): MethodSuite; } export interface BaseMethodSuite { - (methodName: keyof Target, fn: (it: MethodTestFunction) => void): any; + (methodName: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void): any; } export interface MethodSuite extends BaseMethodSuite { only: BaseMethodSuite; diff --git a/build/src/strict-describe-method.js b/build/src/strict-describe-method.js index e6f4708..8b4696d 100644 --- a/build/src/strict-describe-method.js +++ b/build/src/strict-describe-method.js @@ -48,7 +48,7 @@ class MethodDescribeHelper extends StaticMethodDescribeHelper { backup = strict_describers_1.testUtils.prepare(wrapper.target, this.cls.prototype, method); staticBackup = strict_describers_1.testUtils.prepare(this.cls, this.cls); }); - fn(it); + fn(it, () => wrapper.target); afterEach(() => { for (const pair of backup) { wrapper.target[pair[0]] = pair[1]; diff --git a/build/src/strict-describe-method.js.map b/build/src/strict-describe-method.js.map index b364994..a36f074 100644 --- a/build/src/strict-describe-method.js.map +++ b/build/src/strict-describe-method.js.map @@ -1 +1 @@ -{"version":3,"file":"strict-describe-method.js","sourceRoot":"","sources":["../../src/strict-describe-method.ts"],"names":[],"mappings":";;AACA,2DAAyD;AACzD,2CAAwE;AAExE,MAAa,0BAA0B;IACtC,YAA+B,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAI,CAAC;IAExD,0BAA0B,CAAC,KAA8C;QACxE,OAAO,CAAC,MAA6B,EAAE,EAA8B,EAAE,EAAE;YACxE,KAAK,CAAC,iBAAiB,MAAM,EAAE,EAAE,GAAG,EAAE;gBACrC,IAAI,MAAiC,CAAC;gBACtC,UAAU,CAAC,GAAG,EAAE;oBACf,MAAM,GAAG,6BAAS,CAAC,OAAO,CACzB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,GAAG,EACR,MAAM,CACN,CAAC;gBACH,CAAC,CAAC,CAAC;gBAEH,EAAE,CAAC,EAAE,CAAC,CAAC;gBAEP,SAAS,CAAC,GAAG,EAAE;oBACd,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;wBACzB,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;qBACrC;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAA;IACF,CAAC;IAED,oBAAoB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAA8B,CAAC;QACtF,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE7D,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAjCD,gEAiCC;AAED,MAAa,oBAA6B,SAAQ,0BAAkC;IACnF,YACoB,SAAuB,EAC1C,GAAoB;QAEpB,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,CAAC,oBAAoB,CAAC,QAAQ,CAAwB,CAAC;QAC1E,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5C,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAnDD,oDAmDC"} \ No newline at end of file +{"version":3,"file":"strict-describe-method.js","sourceRoot":"","sources":["../../src/strict-describe-method.ts"],"names":[],"mappings":";;AACA,2DAAyD;AACzD,2CAAwE;AAExE,MAAa,0BAA0B;IACtC,YAA+B,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAI,CAAC;IAExD,0BAA0B,CAAC,KAA8C;QACxE,OAAO,CAAC,MAA6B,EAAE,EAA8B,EAAE,EAAE;YACxE,KAAK,CAAC,iBAAiB,MAAM,EAAE,EAAE,GAAG,EAAE;gBACrC,IAAI,MAAiC,CAAC;gBACtC,UAAU,CAAC,GAAG,EAAE;oBACf,MAAM,GAAG,6BAAS,CAAC,OAAO,CACzB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,GAAG,EACR,MAAM,CACN,CAAC;gBACH,CAAC,CAAC,CAAC;gBAEH,EAAE,CAAC,EAAE,CAAC,CAAC;gBAEP,SAAS,CAAC,GAAG,EAAE;oBACd,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;wBACzB,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;qBACrC;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAA;IACF,CAAC;IAED,oBAAoB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAA8B,CA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C,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;qBAC3C;oBACD,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE;wBAC/B,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;qBACrC;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAA;IACF,CAAC;IAED,cAAc;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAwB,CAAC;QAC1E,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5C,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAxDD,oDAwDC"} \ No newline at end of file diff --git a/src/strict-describe-method.ts b/src/strict-describe-method.ts index 6e08277..1821d6b 100644 --- a/src/strict-describe-method.ts +++ b/src/strict-describe-method.ts @@ -46,7 +46,12 @@ export class MethodDescribeHelper extends StaticMethodDescribeHelper void) => void) { - return (method: keyof Target, fn: (it: MethodTestFunction) => void) => { + return (method: keyof Target, + fn: ( + it: MethodTestFunction, + getTarget: () => Target, + ) => void + ) => { const wrapper = {} as TestWrapper; const itHelper = new ItHelper(wrapper); const it = itHelper.createIt(); @@ -66,7 +71,7 @@ export class MethodDescribeHelper extends StaticMethodDescribeHelper wrapper.target); afterEach(() => { for (const pair of backup) { @@ -90,9 +95,8 @@ export class MethodDescribeHelper extends StaticMethodDescribeHelper { - (methodName: keyof Target, fn: (it: MethodTestFunction) => void); + (methodName: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void); } export interface MethodSuite extends BaseMethodSuite {