From 380c78d0ef8d051729786f8a3004068d7393151f Mon Sep 17 00:00:00 2001 From: Thiago Oliveira Santos Date: Sat, 14 Dec 2019 14:04:37 -0300 Subject: [PATCH] Fixing types and creating describeStruct --- build/index.d.ts | 2 +- build/index.js | 2 + build/index.js.map | 2 +- build/strict-describe-class.d.ts | 22 ++++--- build/strict-describe-class.js | 21 ++++++ build/strict-describe-class.js.map | 2 +- build/strict-describe-method.d.ts | 30 ++++----- build/strict-describe-method.js.map | 2 +- src/index.ts | 2 +- src/strict-describe-class.ts | 99 ++++++++++++++++++++--------- src/strict-describe-method.ts | 28 ++++---- 11 files changed, 141 insertions(+), 71 deletions(-) diff --git a/build/index.d.ts b/build/index.d.ts index e0135bc..aa66bc5 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -1,2 +1,2 @@ export { method } from './strict-describers'; -export { describeClass } from './strict-describe-class'; +export { describeClass, describeStaticClass, describeSruct } from './strict-describe-class'; diff --git a/build/index.js b/build/index.js index 03ca514..9927136 100644 --- a/build/index.js +++ b/build/index.js @@ -4,4 +4,6 @@ var strict_describers_1 = require("./strict-describers"); exports.method = strict_describers_1.method; var strict_describe_class_1 = require("./strict-describe-class"); exports.describeClass = strict_describe_class_1.describeClass; +exports.describeStaticClass = strict_describe_class_1.describeStaticClass; +exports.describeSruct = strict_describe_class_1.describeSruct; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map index e4d0dd9..27f07c8 100644 --- a/build/index.js.map +++ b/build/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yDAA6C;AAApC,qCAAA,MAAM,CAAA;AACf,iEAAwD;AAA/C,gDAAA,aAAa,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yDAA6C;AAApC,qCAAA,MAAM,CAAA;AACf,iEAA4F;AAAnF,gDAAA,aAAa,CAAA;AAAE,sDAAA,mBAAmB,CAAA;AAAE,gDAAA,aAAa,CAAA"} \ No newline at end of file diff --git a/build/strict-describe-class.d.ts b/build/strict-describe-class.d.ts index d56ad91..9e3e7c5 100644 --- a/build/strict-describe-class.d.ts +++ b/build/strict-describe-class.d.ts @@ -1,7 +1,8 @@ import { ClassOf } from './strict-describers'; import { MethodSuite, StaticMethodSuite } from './strict-describe-method'; -export declare function mountClassDescribe(cls: ClassOf, bootStrap: () => Target, fn: (describe: MethodSuite) => void, suite: (description: string, fn: () => void) => void): void; -export declare function mountStaticClassDescribe(cls: ClassOf, fn: (describe: StaticMethodSuite) => void, suite: (description: string, fn: () => void) => void): void; +export declare function mountClassDescribe>(cls: Class, bootStrap: () => Target, fn: (describe: MethodSuite) => void, suite: (description: string, fn: () => void) => void): void; +export declare function mountSructDescribe(cls: Target, description: string, fn: (describe: StaticMethodSuite) => void, suite: (description: string, fn: () => void) => void): void; +export declare function mountStaticClassDescribe>(cls: Class, fn: (describe: StaticMethodSuite) => void, suite: (description: string, fn: () => void) => void): void; /** * A describer to create a Test Suite for a single class. * Using this describer is way to enforce a strict organization in the unit test, @@ -20,13 +21,18 @@ export declare function mountStaticClassDescribe(cls: ClassOf, f * will throw an error. This behavior helps to eliminate scope invasion during the tests, and you're assured that no other code * other than the method being tested will run. */ -export declare function describeClass(cls: ClassOf, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; +export declare function describeClass>(cls: Class, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; export declare namespace describeClass { - function only(cls: ClassOf, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; - function skip(cls: ClassOf, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; + function only>(cls: Class, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; + function skip>(cls: Class, bootStrapper: () => Target, fn: (describe: MethodSuite) => void): void; } -export declare function describeStaticClass(cls: ClassOf, fn: (describe: StaticMethodSuite) => void): void; +export declare function describeStaticClass>(cls: Class, fn: (describe: StaticMethodSuite) => void): void; export declare namespace describeStaticClass { - function only(cls: ClassOf, fn: (describe: StaticMethodSuite) => void): void; - function skip(cls: ClassOf, fn: (describe: StaticMethodSuite) => void): void; + function only>(cls: Class, fn: (describe: StaticMethodSuite) => void): void; + function skip>(cls: Class, fn: (describe: StaticMethodSuite) => void): void; +} +export declare function describeSruct(struct: Struct, description: string, fn: (describe: StaticMethodSuite) => void): void; +export declare namespace describeSruct { + function only(struct: Struct, description: string, fn: (describe: StaticMethodSuite) => void): void; + function skip(struct: Struct, description: string, fn: (describe: StaticMethodSuite) => void): void; } diff --git a/build/strict-describe-class.js b/build/strict-describe-class.js index 7aa1f6d..fd3d77d 100644 --- a/build/strict-describe-class.js +++ b/build/strict-describe-class.js @@ -9,6 +9,13 @@ function mountClassDescribe(cls, bootStrap, fn, suite) { }); } exports.mountClassDescribe = mountClassDescribe; +function mountSructDescribe(cls, description, fn, suite) { + const methodDescribeHelper = new strict_describe_method_1.StaticMethodDescribeHelper(cls); + suite(description, () => { + fn(methodDescribeHelper.createStaticDescribe()); + }); +} +exports.mountSructDescribe = mountSructDescribe; function mountStaticClassDescribe(cls, fn, suite) { const methodDescribeHelper = new strict_describe_method_1.StaticMethodDescribeHelper(cls); suite(`static class ${cls.name}`, () => { @@ -62,4 +69,18 @@ exports.describeStaticClass = describeStaticClass; } describeStaticClass.skip = skip; })(describeStaticClass = exports.describeStaticClass || (exports.describeStaticClass = {})); +function describeSruct(struct, description, fn) { + mountSructDescribe(struct, description, fn, mocha_1.describe); +} +exports.describeSruct = describeSruct; +(function (describeSruct) { + function only(struct, description, fn) { + mountSructDescribe(struct, description, fn, mocha_1.describe.only); + } + describeSruct.only = only; + function skip(struct, description, fn) { + mountSructDescribe(struct, description, fn, mocha_1.describe.skip); + } + describeSruct.skip = skip; +})(describeSruct = exports.describeSruct || (exports.describeSruct = {})); //# sourceMappingURL=strict-describe-class.js.map \ No newline at end of file diff --git a/build/strict-describe-class.js.map b/build/strict-describe-class.js.map index b8bcdec..3181dbf 100644 --- a/build/strict-describe-class.js.map +++ b/build/strict-describe-class.js.map @@ -1 +1 @@ -{"version":3,"file":"strict-describe-class.js","sourceRoot":"","sources":["../src/strict-describe-class.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAEjC,qEAA4H;AAE5H,SAAgB,kBAAkB,CACjC,GAAoB,EACpB,SAAuB,EACvB,EAA2C,EAC3C,KAAoD;IAEpD,MAAM,oBAAoB,GAAG,IAAI,6CAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAEtE,KAAK,CAAC,SAAS,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,oBAAoB,CAAC,cAAc,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACJ,CAAC;AAXD,gDAWC;AAED,SAAgB,wBAAwB,CACvC,GAAoB,EACpB,EAAiD,EACjD,KAAoD;IAEpD,MAAM,oBAAoB,GAAG,IAAI,mDAA0B,CAAC,GAAG,CAAC,CAAC;IAEjE,KAAK,CAAC,gBAAgB,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,oBAAoB,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACJ,CAAC;AAVD,4DAUC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,aAAa,CAC5B,GAAoB,EACpB,YAA0B,EAC1B,EAA2C;IAE3C,kBAAkB,CAAS,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,gBAAQ,CAAC,CAAA;AAC5D,CAAC;AAND,sCAMC;AAED,WAAiB,aAAa;IAC7B,SAAgB,IAAI,CACnB,GAAoB,EACpB,YAA0B,EAC1B,EAA2C;QAE3C,kBAAkB,CAAS,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAA;IACjE,CAAC;IANe,kBAAI,OAMnB,CAAA;IAED,SAAgB,IAAI,CACnB,GAAoB,EACpB,YAA0B,EAC1B,EAA2C;QAE3C,kBAAkB,CAAS,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAA;IACjE,CAAC;IANe,kBAAI,OAMnB,CAAA;AACF,CAAC,EAhBgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAgB7B;AAED,SAAgB,mBAAmB,CAClC,GAAoB,EACpB,EAAiD;IAEjD,wBAAwB,CAAS,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,CAAC;AACrD,CAAC;AALD,kDAKC;AAED,WAAiB,mBAAmB;IACnC,SAAgB,IAAI,CACnB,GAAoB,EACpB,EAAiD;QAEjD,wBAAwB,CAAS,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;IALe,wBAAI,OAKnB,CAAA;IAED,SAAgB,IAAI,CACnB,GAAoB,EACpB,EAAiD;QAEjD,wBAAwB,CAAS,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;IALe,wBAAI,OAKnB,CAAA;AACF,CAAC,EAdgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAcnC"} \ No newline at end of file +{"version":3,"file":"strict-describe-class.js","sourceRoot":"","sources":["../src/strict-describe-class.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAEjC,qEAA4H;AAE5H,SAAgB,kBAAkB,CACjC,GAAU,EACV,SAAuB,EACvB,EAAkD,EAClD,KAAoD;IAEpD,MAAM,oBAAoB,GAAG,IAAI,6CAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAEtE,KAAK,CAAC,SAAS,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,oBAAoB,CAAC,cAAc,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACJ,CAAC;AAXD,gDAWC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AAED,SAAgB,mBAAmB,CAClC,GAAU,EACV,EAAgD;IAEhD,wBAAwB,CAAgB,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,CAAC;AAC5D,CAAC;AALD,kDAKC;AAED,WAAiB,mBAAmB;IACnC,SAAgB,IAAI,CACnB,GAAU,EACV,EAAgD;QAEhD,wBAAwB,CAAgB,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IALe,wBAAI,OAKnB,CAAA;IAED,SAAgB,IAAI,CACnB,GAAU,EACV,EAAgD;QAEhD,wBAAwB,CAAgB,GAAG,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IALe,wBAAI,OAKnB,CAAA;AACF,CAAC,EAdgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAcnC;AAID,SAAgB,aAAa,CAC5B,MAAc,EACd,WAAmB,EACnB,EAAiD;IAEjD,kBAAkB,CAAS,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,gBAAQ,CAAC,CAAC;AAC/D,CAAC;AAND,sCAMC;AAED,WAAiB,aAAa;IAC7B,SAAgB,IAAI,CACnB,MAAc,EACd,WAAmB,EACnB,EAAiD;QAEjD,kBAAkB,CAAS,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IANe,kBAAI,OAMnB,CAAA;IAED,SAAgB,IAAI,CACnB,MAAc,EACd,WAAmB,EACnB,EAAiD;QAEjD,kBAAkB,CAAS,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,gBAAQ,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IANe,kBAAI,OAMnB,CAAA;AACF,CAAC,EAhBgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAgB7B"} \ No newline at end of file diff --git a/build/strict-describe-method.d.ts b/build/strict-describe-method.d.ts index 149edc3..1f77359 100644 --- a/build/strict-describe-method.d.ts +++ b/build/strict-describe-method.d.ts @@ -1,30 +1,30 @@ import { TestFunction } from "mocha"; import { ClassOf } from "./strict-describers"; import { MethodTestFunction } from "./strict-it"; -export declare class StaticMethodDescribeHelper { - protected readonly cls: ClassOf; - constructor(cls: ClassOf); - createSingleStaticDescribe(suite: (title: string, fn: () => void) => void): (method: "prototype" | "name", fn: (it: TestFunction) => void) => void; - createStaticDescribe(): StaticMethodSuite; +export declare class StaticMethodDescribeHelper { + protected readonly cls: Class; + constructor(cls: Class); + createSingleStaticDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Class, fn: (it: TestFunction) => void) => void; + createStaticDescribe(): StaticMethodSuite; } -export declare class MethodDescribeHelper extends StaticMethodDescribeHelper { +export declare class MethodDescribeHelper> extends StaticMethodDescribeHelper { protected readonly bootstrap: () => Target; - constructor(bootstrap: () => Target, cls: ClassOf); + constructor(bootstrap: () => Target, cls: Class); createMethodDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void) => void; - createDescribe(): MethodSuite; + createDescribe(): MethodSuite; } export interface BaseMethodSuite { (methodName: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void): any; } -export interface MethodSuite extends BaseMethodSuite { +export interface MethodSuite> extends BaseMethodSuite { only: BaseMethodSuite; skip: BaseMethodSuite; - static: StaticMethodSuite; + static: StaticMethodSuite; } -export interface BaseStaticMethodSuite { - (methodName: keyof ClassOf, fn: (it: TestFunction) => void): any; +export interface BaseStaticMethodSuite { + (methodName: keyof Class, fn: (it: TestFunction) => void): any; } -export interface StaticMethodSuite extends BaseStaticMethodSuite { - only: BaseStaticMethodSuite; - skip: BaseStaticMethodSuite; +export interface StaticMethodSuite extends BaseStaticMethodSuite { + only: BaseStaticMethodSuite; + skip: BaseStaticMethodSuite; } diff --git a/build/strict-describe-method.js.map b/build/strict-describe-method.js.map index d289eb7..c3d85f6 100644 --- a/build/strict-describe-method.js.map +++ b/build/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,KAAK,CAAC,GAAG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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 +{"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,GAAU;QAAV,QAAG,GAAH,GAAG,CAAO;IAAI,CAAC;IAE9C,0BAA0B,CAAC,KAA8C;QACxE,OAAO,CAAC,MAAmB,EAAE,EAA8B,EAAE,EAAE;YAC9D,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,C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E;wBACzB,OAAO,CAAC,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,CAA+B,CAAC;QACjF,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/index.ts b/src/index.ts index 4e817d0..8ad6df0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ export { method } from './strict-describers'; -export { describeClass } from './strict-describe-class'; +export { describeClass, describeStaticClass, describeSruct } from './strict-describe-class'; diff --git a/src/strict-describe-class.ts b/src/strict-describe-class.ts index 60b0d8a..fe0d2ab 100644 --- a/src/strict-describe-class.ts +++ b/src/strict-describe-class.ts @@ -2,10 +2,10 @@ import { describe } from 'mocha'; import { ClassOf } from './strict-describers'; import { MethodSuite, MethodDescribeHelper, StaticMethodSuite, StaticMethodDescribeHelper } from './strict-describe-method'; -export function mountClassDescribe( - cls: ClassOf, +export function mountClassDescribe>( + cls: Class, bootStrap: () => Target, - fn: (describe: MethodSuite) => void, + fn: (describe: MethodSuite) => void, suite: (description: string, fn: () => void) => void, ) { const methodDescribeHelper = new MethodDescribeHelper(bootStrap, cls); @@ -15,13 +15,26 @@ export function mountClassDescribe( }); } -export function mountStaticClassDescribe( - cls: ClassOf, +export function mountSructDescribe( + cls: Target, + description: string, fn: (describe: StaticMethodSuite) => void, suite: (description: string, fn: () => void) => void, ) { const methodDescribeHelper = new StaticMethodDescribeHelper(cls); + suite(description, () => { + fn(methodDescribeHelper.createStaticDescribe()); + }); +} + +export function mountStaticClassDescribe>( + cls: Class, + fn: (describe: StaticMethodSuite) => void, + suite: (description: string, fn: () => void) => void, +) { + const methodDescribeHelper = new StaticMethodDescribeHelper(cls); + suite(`static class ${cls.name}`, () => { fn(methodDescribeHelper.createStaticDescribe()); }); @@ -45,51 +58,79 @@ export function mountStaticClassDescribe( * will throw an error. This behavior helps to eliminate scope invasion during the tests, and you're assured that no other code * other than the method being tested will run. */ -export function describeClass ( - cls: ClassOf, +export function describeClass> ( + cls: Class, bootStrapper: () => Target, - fn: (describe: MethodSuite) => void + fn: (describe: MethodSuite) => void ) { - mountClassDescribe(cls, bootStrapper, fn, describe) + mountClassDescribe(cls, bootStrapper, fn, describe) } export namespace describeClass { - export function only ( - cls: ClassOf, + export function only> ( + cls: Class, bootStrapper: () => Target, - fn: (describe: MethodSuite) => void + fn: (describe: MethodSuite) => void ) { - mountClassDescribe(cls, bootStrapper, fn, describe.only) + mountClassDescribe(cls, bootStrapper, fn, describe.only) } - export function skip ( - cls: ClassOf, + export function skip> ( + cls: Class, bootStrapper: () => Target, - fn: (describe: MethodSuite) => void + fn: (describe: MethodSuite) => void ) { - mountClassDescribe(cls, bootStrapper, fn, describe.skip) + mountClassDescribe(cls, bootStrapper, fn, describe.skip) } } -export function describeStaticClass ( - cls: ClassOf, - fn: (describe: StaticMethodSuite) => void +export function describeStaticClass> ( + cls: Class, + fn: (describe: StaticMethodSuite) => void ) { - mountStaticClassDescribe(cls, fn, describe); + mountStaticClassDescribe(cls, fn, describe); } export namespace describeStaticClass { - export function only ( - cls: ClassOf, - fn: (describe: StaticMethodSuite) => void + export function only> ( + cls: Class, + fn: (describe: StaticMethodSuite) => void + ) { + mountStaticClassDescribe(cls, fn, describe.only); + } + + export function skip> ( + cls: Class, + fn: (describe: StaticMethodSuite) => void + ) { + mountStaticClassDescribe(cls, fn, describe.skip); + } +} + + + +export function describeSruct ( + struct: Struct, + description: string, + fn: (describe: StaticMethodSuite) => void +) { + mountSructDescribe(struct, description, fn, describe); +} + +export namespace describeSruct { + export function only ( + struct: Struct, + description: string, + fn: (describe: StaticMethodSuite) => void ) { - mountStaticClassDescribe(cls, fn, describe.only); + mountSructDescribe(struct, description, fn, describe.only); } - export function skip ( - cls: ClassOf, - fn: (describe: StaticMethodSuite) => void + export function skip ( + struct: Struct, + description: string, + fn: (describe: StaticMethodSuite) => void ) { - mountStaticClassDescribe(cls, fn, describe.skip); + mountSructDescribe(struct, description, fn, describe.skip); } } diff --git a/src/strict-describe-method.ts b/src/strict-describe-method.ts index 1821d6b..6b4b713 100644 --- a/src/strict-describe-method.ts +++ b/src/strict-describe-method.ts @@ -2,11 +2,11 @@ import { TestFunction } from "mocha"; import { ClassOf, testUtils } from "./strict-describers"; import { MethodTestFunction, TestWrapper, ItHelper } from "./strict-it"; -export class StaticMethodDescribeHelper { - constructor(protected readonly cls: ClassOf) { } +export class StaticMethodDescribeHelper { + constructor(protected readonly cls: Class) { } createSingleStaticDescribe(suite: (title: string, fn: () => void) => void) { - return (method: keyof ClassOf, fn: (it: TestFunction) => void) => { + return (method: keyof Class, fn: (it: TestFunction) => void) => { suite(`static method ${method}`, () => { let backup: Array<[string, Function]>; beforeEach(() => { @@ -29,7 +29,7 @@ export class StaticMethodDescribeHelper { } createStaticDescribe() { - const result = this.createSingleStaticDescribe(describe) as StaticMethodSuite; + const result = this.createSingleStaticDescribe(describe) as StaticMethodSuite; result.skip = this.createSingleStaticDescribe(describe.skip); result.only = this.createSingleStaticDescribe(describe.only); @@ -37,10 +37,10 @@ export class StaticMethodDescribeHelper { } } -export class MethodDescribeHelper extends StaticMethodDescribeHelper { +export class MethodDescribeHelper> extends StaticMethodDescribeHelper { constructor( protected readonly bootstrap: () => Target, - cls: ClassOf + cls: Class ) { super(cls); } @@ -86,7 +86,7 @@ export class MethodDescribeHelper extends StaticMethodDescribeHelper; + const result = this.createMethodDescribe(describe) as MethodSuite; result.skip = this.createMethodDescribe(describe.skip); result.only = this.createMethodDescribe(describe.only); result.static = this.createStaticDescribe(); @@ -99,17 +99,17 @@ export interface BaseMethodSuite { (methodName: keyof Target, fn: (it: MethodTestFunction, getTarget: () => Target) => void); } -export interface MethodSuite extends BaseMethodSuite { +export interface MethodSuite> extends BaseMethodSuite { only: BaseMethodSuite; skip: BaseMethodSuite; - static: StaticMethodSuite; + static: StaticMethodSuite; } -export interface BaseStaticMethodSuite { - (methodName: keyof ClassOf, fn: (it: TestFunction) => void); +export interface BaseStaticMethodSuite { + (methodName: keyof Class, fn: (it: TestFunction) => void); } -export interface StaticMethodSuite extends BaseStaticMethodSuite { - only: BaseStaticMethodSuite; - skip: BaseStaticMethodSuite; +export interface StaticMethodSuite extends BaseStaticMethodSuite { + only: BaseStaticMethodSuite; + skip: BaseStaticMethodSuite; }