diff --git a/dist/spec/issues/11.test.js.map b/dist/spec/issues/11.test.js.map index 10abed8..7c46132 100644 --- a/dist/spec/issues/11.test.js.map +++ b/dist/spec/issues/11.test.js.map @@ -1 +1 @@ -{"version":3,"file":"11.test.js","sourceRoot":"","sources":["../../../spec/issues/11.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA2BG;;AA3BH,2BAAuB;AACvB,yCAAkD;AAOlD;IAAA;IAIA,CAAC;IAHG,4BAAG,GAAH,UAAI,OAAgB;QAChB,OAAO,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACrC,CAAC;IACL,qBAAC;AAAD,CAAC,AAJD,IAIC;AAED,aAAI,CAAC,sCAAsC,EAAE,UAAM,CAAC;;;QAC5C,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAkB,CAAC;QACxD,gBAAgB,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAEvC,KAAK,GAAG,CAAC,CAAC;QACd,gBAAgB,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAEzC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC;YACrC,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC,CAAC;QAEJ,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;;;KAClB,CAAC,CAAC","sourcesContent":["import test from 'ava';\nimport { Substitute, Arg } from '../../src/index';\n\ntype Addands = {\n op1: number;\n op2: number;\n}\n\nclass RealCalculator {\n add(addands: Addands): number {\n return addands.op1 + addands.op2;\n }\n}\n\ntest('issue 11: arg.is is only called once', async t => {\n let mockedCalculator = Substitute.for();\n mockedCalculator.add(Arg.any()).returns(4);\n\n let count = 0;\n mockedCalculator.add({ op1: 1, op2: 2 });\n\n mockedCalculator.received(1).add(Arg.is(a => {\n count++;\n return a.op1 === 1 && a.op2 === 2;\n }));\n\n t.is(count, 1);\n});"]} \ No newline at end of file +{"version":3,"file":"11.test.js","sourceRoot":"","sources":["../../../spec/issues/11.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA2BG;;AA3BH,2BAAuB;AACvB,yCAAkD;AAOlD;IAAA;IAIA,CAAC;IAHG,4BAAG,GAAH,UAAI,OAAgB;QAChB,OAAO,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACrC,CAAC;IACL,qBAAC;AAAD,CAAC,AAJD,IAIC;AAED,aAAI,CAAC,sCAAsC,EAAE,UAAM,CAAC;;;QAC5C,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAkB,CAAC;QACxD,gBAAgB,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAEvC,KAAK,GAAG,CAAC,CAAC;QACd,gBAAgB,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAEzC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC;YACrC,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC,CAAC;QAEJ,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;;;KAClB,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\nimport { Substitute, Arg } from '../../src/index';\r\n\r\ntype Addands = {\r\n op1: number;\r\n op2: number;\r\n}\r\n\r\nclass RealCalculator {\r\n add(addands: Addands): number {\r\n return addands.op1 + addands.op2;\r\n }\r\n}\r\n\r\ntest('issue 11: arg.is is only called once', async t => {\r\n let mockedCalculator = Substitute.for();\r\n mockedCalculator.add(Arg.any()).returns(4);\r\n\r\n let count = 0;\r\n mockedCalculator.add({ op1: 1, op2: 2 });\r\n\r\n mockedCalculator.received(1).add(Arg.is(a => {\r\n count++;\r\n return a.op1 === 1 && a.op2 === 2;\r\n }));\r\n\r\n t.is(count, 1);\r\n});"]} \ No newline at end of file diff --git a/dist/spec/issues/15.test.js.map b/dist/spec/issues/15.test.js.map index aa7ecc3..2364d05 100644 --- a/dist/spec/issues/15.test.js.map +++ b/dist/spec/issues/15.test.js.map @@ -1 +1 @@ -{"version":3,"file":"15.test.js","sourceRoot":"","sources":["../../../spec/issues/15.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAA6C;AAM7C,aAAI,CAAC,qCAAqC,EAAE,UAAA,CAAC;IACzC,IAAM,GAAG,GAAG,KAAK,CAAC;IAClB,IAAM,GAAG,GAAG,kBAAU,CAAC,GAAG,EAAW,CAAC;IAEtC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErB,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IACtB,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IAEtB,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\n\nimport { Substitute } from '../../src/index';\n\nexport interface Example {\n bar: string;\n}\n\ntest('issue 15: can call properties twice', t => {\n const baz = \"baz\";\n const foo = Substitute.for();\n\n foo.bar.returns(baz);\n\n const call1 = foo.bar;\n const call2 = foo.bar;\n\n t.is(call1, baz);\n t.is(call2, baz);\n});"]} \ No newline at end of file +{"version":3,"file":"15.test.js","sourceRoot":"","sources":["../../../spec/issues/15.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAA6C;AAM7C,aAAI,CAAC,qCAAqC,EAAE,UAAA,CAAC;IACzC,IAAM,GAAG,GAAG,KAAK,CAAC;IAClB,IAAM,GAAG,GAAG,kBAAU,CAAC,GAAG,EAAW,CAAC;IAEtC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErB,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IACtB,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IAEtB,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute } from '../../src/index';\r\n\r\nexport interface Example {\r\n bar: string;\r\n}\r\n\r\ntest('issue 15: can call properties twice', t => {\r\n const baz = \"baz\";\r\n const foo = Substitute.for();\r\n\r\n foo.bar.returns(baz);\r\n\r\n const call1 = foo.bar;\r\n const call2 = foo.bar;\r\n\r\n t.is(call1, baz);\r\n t.is(call2, baz);\r\n});"]} \ No newline at end of file diff --git a/dist/spec/issues/18.test.js.map b/dist/spec/issues/18.test.js.map index cb4a459..cd0164a 100644 --- a/dist/spec/issues/18.test.js.map +++ b/dist/spec/issues/18.test.js.map @@ -1 +1 @@ -{"version":3,"file":"18.test.js","sourceRoot":"","sources":["../../../spec/issues/18.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,4BAA4B,EAAE,UAAA,CAAC;IAChC,IAAM,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IAC/D,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,WAAG,CAAC,EAAE,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjE,KAAK,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEhC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,WAAG,CAAC,EAAE,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC;IAElE,CAAC,CAAC,IAAI,EAAE,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\n\nimport { Substitute, Arg } from '../../src/index';\n\ninterface CalculatorInterface {\n add(a: number, b: number): number\n subtract(a: number, b: number): number\n divide(a: number, b: number): number\n isEnabled: boolean\n}\n\ntest('issue 18: receive with arg', t => {\n const mockedCalculator = Substitute.for();\n mockedCalculator.add(1, Arg.is(input => input === 2)).returns(4);\n\n void mockedCalculator.add(1, 2);\n\n mockedCalculator.received(1).add(1, Arg.is(input => input === 2));\n\n t.pass();\n});"]} \ No newline at end of file +{"version":3,"file":"18.test.js","sourceRoot":"","sources":["../../../spec/issues/18.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,4BAA4B,EAAE,UAAA,CAAC;IAChC,IAAM,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IAC/D,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,WAAG,CAAC,EAAE,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjE,KAAK,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEhC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,WAAG,CAAC,EAAE,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC;IAElE,CAAC,CAAC,IAAI,EAAE,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute, Arg } from '../../src/index';\r\n\r\ninterface CalculatorInterface {\r\n add(a: number, b: number): number\r\n subtract(a: number, b: number): number\r\n divide(a: number, b: number): number\r\n isEnabled: boolean\r\n}\r\n\r\ntest('issue 18: receive with arg', t => {\r\n const mockedCalculator = Substitute.for();\r\n mockedCalculator.add(1, Arg.is(input => input === 2)).returns(4);\r\n\r\n void mockedCalculator.add(1, 2);\r\n\r\n mockedCalculator.received(1).add(1, Arg.is(input => input === 2));\r\n\r\n t.pass();\r\n});"]} \ No newline at end of file diff --git a/dist/spec/issues/23.test.js.map b/dist/spec/issues/23.test.js.map index ee9e5f4..637b806 100644 --- a/dist/spec/issues/23.test.js.map +++ b/dist/spec/issues/23.test.js.map @@ -1 +1 @@ -{"version":3,"file":"23.test.js","sourceRoot":"","sources":["../../../spec/issues/23.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,kDAAkD,EAAE,UAAA,CAAC;IACxD,IAAM,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IAE/D,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,gBAAgB,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,UAAC,CAAC,EAAE,CAAC;QAC3C,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAA;QAC9C,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK;IAEjC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,4BAA4B;AACrE,CAAC,CAAC,CAAC","sourcesContent":["import test from \"ava\";\n\nimport { Substitute, Arg } from \"../../src/index\";\n\ninterface CalculatorInterface {\n add(a: number, b: number): number;\n subtract(a: number, b: number): number;\n divide(a: number, b: number): number;\n isEnabled: boolean;\n}\n\ntest(\"issue 23: mimick received should not call method\", t => {\n const mockedCalculator = Substitute.for();\n\n let calls = 0\n\n mockedCalculator.add(Arg.all()).mimicks((a, b) => {\n t.deepEqual(++calls, 1, 'mimick called twice')\n return a + b;\n });\n\n mockedCalculator.add(1, 1); // ok\n\n mockedCalculator.received(1).add(1, 1) // not ok, calls mimick func\n});\n"]} \ No newline at end of file +{"version":3,"file":"23.test.js","sourceRoot":"","sources":["../../../spec/issues/23.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,kDAAkD,EAAE,UAAA,CAAC;IACxD,IAAM,gBAAgB,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IAE/D,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,gBAAgB,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,UAAC,CAAC,EAAE,CAAC;QAC3C,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAA;QAC9C,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK;IAEjC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,4BAA4B;AACrE,CAAC,CAAC,CAAC","sourcesContent":["import test from \"ava\";\r\n\r\nimport { Substitute, Arg } from \"../../src/index\";\r\n\r\ninterface CalculatorInterface {\r\n add(a: number, b: number): number;\r\n subtract(a: number, b: number): number;\r\n divide(a: number, b: number): number;\r\n isEnabled: boolean;\r\n}\r\n\r\ntest(\"issue 23: mimick received should not call method\", t => {\r\n const mockedCalculator = Substitute.for();\r\n\r\n let calls = 0\r\n\r\n mockedCalculator.add(Arg.all()).mimicks((a, b) => {\r\n t.deepEqual(++calls, 1, 'mimick called twice')\r\n return a + b;\r\n });\r\n\r\n mockedCalculator.add(1, 1); // ok\r\n\r\n mockedCalculator.received(1).add(1, 1) // not ok, calls mimick func\r\n});\r\n"]} \ No newline at end of file diff --git a/dist/spec/issues/25.test.js.map b/dist/spec/issues/25.test.js.map index 69c4d0f..3406037 100644 --- a/dist/spec/issues/25.test.js.map +++ b/dist/spec/issues/25.test.js.map @@ -1 +1 @@ -{"version":3,"file":"25.test.js","sourceRoot":"","sources":["../../../spec/issues/25.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,YAAY,EAAE,UAAA,CAAC;IAChB,IAAM,IAAI,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IACnD,IAAI,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEf,CAAC,CAAC,SAAS,CAAC,cAAM,OAAA,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAzB,CAAyB,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,0FAA0F,EAAE,UAAA,CAAC;IAC9F,IAAM,IAAI,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IACnD,IAAI,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEf,CAAC,CAAC,MAAM,CAAC,cAAM,OAAA,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAzB,CAAyB,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\n\nimport { Substitute, Arg } from '../../src/index';\n\ninterface CalculatorInterface {\n add(a: number, b: number): number\n subtract(a: number, b: number): number\n divide(a: number, b: number): number\n isEnabled: boolean\n}\n\ntest('issue 25_2', t => {\n const calc = Substitute.for();\n calc.add(Arg.all()).returns(1337);\n calc.add(2, 5);\n\n t.notThrows(() => calc.received().add(2, 5));\n});\n\ntest('issue 25_1: call verification does not work when using Arg.all() to set up return values', t => {\n const calc = Substitute.for();\n calc.add(Arg.all()).returns(1337);\n calc.add(2, 5);\n\n t.throws(() => calc.received().add(3, 4));\n});"]} \ No newline at end of file +{"version":3,"file":"25.test.js","sourceRoot":"","sources":["../../../spec/issues/25.test.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,yCAAkD;AASlD,aAAI,CAAC,YAAY,EAAE,UAAA,CAAC;IAChB,IAAM,IAAI,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IACnD,IAAI,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEf,CAAC,CAAC,SAAS,CAAC,cAAM,OAAA,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAzB,CAAyB,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,0FAA0F,EAAE,UAAA,CAAC;IAC9F,IAAM,IAAI,GAAG,kBAAU,CAAC,GAAG,EAAuB,CAAC;IACnD,IAAI,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEf,CAAC,CAAC,MAAM,CAAC,cAAM,OAAA,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAzB,CAAyB,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute, Arg } from '../../src/index';\r\n\r\ninterface CalculatorInterface {\r\n add(a: number, b: number): number\r\n subtract(a: number, b: number): number\r\n divide(a: number, b: number): number\r\n isEnabled: boolean\r\n}\r\n\r\ntest('issue 25_2', t => {\r\n const calc = Substitute.for();\r\n calc.add(Arg.all()).returns(1337);\r\n calc.add(2, 5);\r\n\r\n t.notThrows(() => calc.received().add(2, 5));\r\n});\r\n\r\ntest('issue 25_1: call verification does not work when using Arg.all() to set up return values', t => {\r\n const calc = Substitute.for();\r\n calc.add(Arg.all()).returns(1337);\r\n calc.add(2, 5);\r\n\r\n t.throws(() => calc.received().add(3, 4));\r\n});"]} \ No newline at end of file diff --git a/dist/spec/issues/8.test.js.map b/dist/spec/issues/8.test.js.map index bdfadab..8ef1476 100644 --- a/dist/spec/issues/8.test.js.map +++ b/dist/spec/issues/8.test.js.map @@ -1 +1 @@ -{"version":3,"file":"8.test.js","sourceRoot":"","sources":["../../../spec/issues/8.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAuCG;;AAvCH,yCAAyC;AACzC,2BAAuB;AAEvB;IACC;IAAc,CAAC;IAEf,wBAAO,GAAP;QACC,OAAO,KAAK,CAAA;IACb,CAAC;IACF,aAAC;AAAD,CAAC,AAND,IAMC;AAED;IACC,gBACS,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,wBAAO,GAAP;QACC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,yBAAQ,GAAR;QACC,OAAO,KAAK,CAAA;IACb,CAAC;IACF,aAAC;AAAD,CAAC,AAZD,IAYC;AAED;IACC,gBACS,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,wBAAO,GAAP;QACC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IACF,aAAC;AAAD,CAAC,AARD,IAQC;AAED,aAAI,CAAC,0CAA0C,EAAE,UAAM,CAAC;;;QAC9C,UAAU,GAAG,eAAU,CAAC,GAAG,EAAU,CAAC;QACtC,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;;KACvB,CAAC,CAAC","sourcesContent":["import Substitute from \"../../src/index\";\nimport test from 'ava';\n\nclass ClassA {\n\tconstructor(){}\n\n\tmethodA(): string {\n\t\treturn 'abc'\n\t}\n}\n\nclass ClassB {\n\tconstructor(\n\t\tprivate classA: ClassA\n\t) {}\n\n\tmethodB(): string {\n\t\treturn this.classA.methodA();\n\t}\n\n\tmethodB2(): string {\n\t\treturn 'def'\n\t}\n}\n\nclass ClassC {\n\tconstructor(\n\t\tprivate classB: ClassB\n\t) {}\n\n\tmethodC(): string {\n\t\treturn this.classB.methodB2();\n\t}\n}\n\ntest('issue 8: can use substitute in arguments', async t => {\n const classBMock = Substitute.for();\n const classC = new ClassC(classBMock);\n t.not(classC, null);\n});"]} \ No newline at end of file +{"version":3,"file":"8.test.js","sourceRoot":"","sources":["../../../spec/issues/8.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAuCG;;AAvCH,yCAAyC;AACzC,2BAAuB;AAEvB;IACC;IAAc,CAAC;IAEf,wBAAO,GAAP;QACC,OAAO,KAAK,CAAA;IACb,CAAC;IACF,aAAC;AAAD,CAAC,AAND,IAMC;AAED;IACC,gBACS,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,wBAAO,GAAP;QACC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,yBAAQ,GAAR;QACC,OAAO,KAAK,CAAA;IACb,CAAC;IACF,aAAC;AAAD,CAAC,AAZD,IAYC;AAED;IACC,gBACS,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,wBAAO,GAAP;QACC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IACF,aAAC;AAAD,CAAC,AARD,IAQC;AAED,aAAI,CAAC,0CAA0C,EAAE,UAAM,CAAC;;;QAC9C,UAAU,GAAG,eAAU,CAAC,GAAG,EAAU,CAAC;QACtC,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;;KACvB,CAAC,CAAC","sourcesContent":["import Substitute from \"../../src/index\";\r\nimport test from 'ava';\r\n\r\nclass ClassA {\r\n\tconstructor(){}\r\n\r\n\tmethodA(): string {\r\n\t\treturn 'abc'\r\n\t}\r\n}\r\n\r\nclass ClassB {\r\n\tconstructor(\r\n\t\tprivate classA: ClassA\r\n\t) {}\r\n\r\n\tmethodB(): string {\r\n\t\treturn this.classA.methodA();\r\n\t}\r\n\r\n\tmethodB2(): string {\r\n\t\treturn 'def'\r\n\t}\r\n}\r\n\r\nclass ClassC {\r\n\tconstructor(\r\n\t\tprivate classB: ClassB\r\n\t) {}\r\n\r\n\tmethodC(): string {\r\n\t\treturn this.classB.methodB2();\r\n\t}\r\n}\r\n\r\ntest('issue 8: can use substitute in arguments', async t => {\r\n const classBMock = Substitute.for();\r\n const classC = new ClassC(classBMock);\r\n t.not(classC, null);\r\n});"]} \ No newline at end of file diff --git a/dist/src/Arguments.js b/dist/src/Arguments.js index b44a0bc..64a77b8 100644 --- a/dist/src/Arguments.js +++ b/dist/src/Arguments.js @@ -5,7 +5,7 @@ var __extends = (this && this.__extends) || (function () { ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); - }; + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } diff --git a/dist/src/Substitute.d.ts b/dist/src/Substitute.d.ts index 5da109f..3e8bab3 100644 --- a/dist/src/Substitute.d.ts +++ b/dist/src/Substitute.d.ts @@ -1,7 +1,8 @@ import { ObjectSubstitute, OmitProxyMethods, DisabledSubstituteObject } from "./Transformations"; export declare const HandlerKey: unique symbol; export declare const AreProxiesDisabledKey: unique symbol; +export declare type SubstituteOf = ObjectSubstitute, T> & T; export declare class Substitute { - static for(): ObjectSubstitute, T> & T; + static for(): SubstituteOf; static disableFor>>(substitute: T): DisabledSubstituteObject; } diff --git a/dist/src/Substitute.js.map b/dist/src/Substitute.js.map index 8d78043..3b8bcf3 100644 --- a/dist/src/Substitute.js.map +++ b/dist/src/Substitute.js.map @@ -1 +1 @@ -{"version":3,"file":"Substitute.js","sourceRoot":"","sources":["../../src/Substitute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAGvB,QAAA,UAAU,GAAG,MAAM,EAAE,CAAC;AACtB,QAAA,qBAAqB,GAAG,MAAM,EAAE,CAAC;AAE9C;IAAA;IAyBA,CAAC;IAxBU,cAAG,GAAV;QACI,IAAM,aAAa,GAAG,IAAI,iBAAO,EAAE,CAAC;QACpC,OAAO,aAAa,CAAC,SAAS,CAAC;IACnC,CAAC;IAEM,qBAAU,GAAjB,UAAqE,UAAa;QAC9E,IAAM,SAAS,GAAG,UAAiB,CAAC;QACpC,IAAM,gBAAgB,GAAG,SAAS,CAAC,kBAAU,CAAC,CAAC;QAE/C,IAAM,YAAY,GAAG,UAAqB,CAAI;YAC1C,OAAO;gBACH,SAAS,CAAC,6BAAqB,CAAC,GAAG,IAAI,CAAC;gBACxC,IAAM,WAAW,GAAG,CAAC,CAAC,IAAI,OAAN,CAAC,YAAM,gBAAgB,GAAK,SAAS,EAAC,CAAC;gBAC3D,SAAS,CAAC,6BAAqB,CAAC,GAAG,KAAK,CAAC;gBACzC,OAAO,WAAW,CAAC;YACvB,CAAQ,CAAC;QACb,CAAC,CAAC;QAEF,OAAO,IAAI,KAAK,CAAC,cAAQ,CAAC,EAAE;YACxB,KAAK,EAAE,YAAY,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC3C,GAAG,EAAE,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC;YACvC,GAAG,EAAE,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC;SAC1C,CAAQ,CAAC;IACd,CAAC;IACL,iBAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,gCAAU","sourcesContent":["import { Context } from \"./Context\";\r\nimport { ObjectSubstitute, OmitProxyMethods, DisabledSubstituteObject } from \"./Transformations\";\r\n\r\nexport const HandlerKey = Symbol();\r\nexport const AreProxiesDisabledKey = Symbol();\r\n\r\nexport class Substitute {\r\n static for(): ObjectSubstitute, T> & T {\r\n const objectContext = new Context();\r\n return objectContext.rootProxy;\r\n }\r\n\r\n static disableFor>>(substitute: T): DisabledSubstituteObject {\r\n const thisProxy = substitute as any;\r\n const thisExposedProxy = thisProxy[HandlerKey];\r\n\r\n const disableProxy = (f: K): K => {\r\n return function() {\r\n thisProxy[AreProxiesDisabledKey] = true;\r\n const returnValue = f.call(thisExposedProxy, ...arguments);\r\n thisProxy[AreProxiesDisabledKey] = false;\r\n return returnValue;\r\n } as any;\r\n };\r\n\r\n return new Proxy(() => { }, {\r\n apply: disableProxy(thisExposedProxy.apply),\r\n set: disableProxy(thisExposedProxy.set),\r\n get: disableProxy(thisExposedProxy.get)\r\n }) as any;\r\n }\r\n}"]} \ No newline at end of file +{"version":3,"file":"Substitute.js","sourceRoot":"","sources":["../../src/Substitute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAGvB,QAAA,UAAU,GAAG,MAAM,EAAE,CAAC;AACtB,QAAA,qBAAqB,GAAG,MAAM,EAAE,CAAC;AAI9C;IAAA;IAyBA,CAAC;IAxBU,cAAG,GAAV;QACI,IAAM,aAAa,GAAG,IAAI,iBAAO,EAAE,CAAC;QACpC,OAAO,aAAa,CAAC,SAAS,CAAC;IACnC,CAAC;IAEM,qBAAU,GAAjB,UAAqE,UAAa;QAC9E,IAAM,SAAS,GAAG,UAAiB,CAAC;QACpC,IAAM,gBAAgB,GAAG,SAAS,CAAC,kBAAU,CAAC,CAAC;QAE/C,IAAM,YAAY,GAAG,UAAqB,CAAI;YAC1C,OAAO;gBACH,SAAS,CAAC,6BAAqB,CAAC,GAAG,IAAI,CAAC;gBACxC,IAAM,WAAW,GAAG,CAAC,CAAC,IAAI,OAAN,CAAC,YAAM,gBAAgB,GAAK,SAAS,EAAC,CAAC;gBAC3D,SAAS,CAAC,6BAAqB,CAAC,GAAG,KAAK,CAAC;gBACzC,OAAO,WAAW,CAAC;YACvB,CAAQ,CAAC;QACb,CAAC,CAAC;QAEF,OAAO,IAAI,KAAK,CAAC,cAAQ,CAAC,EAAE;YACxB,KAAK,EAAE,YAAY,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC3C,GAAG,EAAE,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC;YACvC,GAAG,EAAE,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC;SAC1C,CAAQ,CAAC;IACd,CAAC;IACL,iBAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,gCAAU","sourcesContent":["import { Context } from \"./Context\";\r\nimport { ObjectSubstitute, OmitProxyMethods, DisabledSubstituteObject } from \"./Transformations\";\r\n\r\nexport const HandlerKey = Symbol();\r\nexport const AreProxiesDisabledKey = Symbol();\r\n\r\nexport type SubstituteOf = ObjectSubstitute, T> & T;\r\n\r\nexport class Substitute {\r\n static for(): SubstituteOf {\r\n const objectContext = new Context();\r\n return objectContext.rootProxy;\r\n }\r\n\r\n static disableFor>>(substitute: T): DisabledSubstituteObject {\r\n const thisProxy = substitute as any;\r\n const thisExposedProxy = thisProxy[HandlerKey];\r\n\r\n const disableProxy = (f: K): K => {\r\n return function() {\r\n thisProxy[AreProxiesDisabledKey] = true;\r\n const returnValue = f.call(thisExposedProxy, ...arguments);\r\n thisProxy[AreProxiesDisabledKey] = false;\r\n return returnValue;\r\n } as any;\r\n };\r\n\r\n return new Proxy(() => { }, {\r\n apply: disableProxy(thisExposedProxy.apply),\r\n set: disableProxy(thisExposedProxy.set),\r\n get: disableProxy(thisExposedProxy.get)\r\n }) as any;\r\n }\r\n}"]} \ No newline at end of file diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts index dbf5915..3a45d48 100644 --- a/dist/src/index.d.ts +++ b/dist/src/index.d.ts @@ -1,4 +1,4 @@ -import { Substitute } from './Substitute'; +import { Substitute, SubstituteOf } from './Substitute'; export { Arg } from './Arguments'; -export { Substitute }; +export { Substitute, SubstituteOf }; export default Substitute; diff --git a/dist/src/index.js.map b/dist/src/index.js.map index 5f4ebee..f006580 100644 --- a/dist/src/index.js.map +++ b/dist/src/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,2CAA0C;AAGjC,qBAHA,uBAAU,CAGA;AADnB,yCAAkC;AAAzB,0BAAA,GAAG,CAAA;AAGZ,kBAAe,uBAAU,CAAC","sourcesContent":["import { Substitute } from './Substitute';\n\nexport { Arg } from './Arguments';\nexport { Substitute };\n\nexport default Substitute;"]} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,2CAAwD;AAG/C,qBAHA,uBAAU,CAGA;AADnB,yCAAkC;AAAzB,0BAAA,GAAG,CAAA;AAGZ,kBAAe,uBAAU,CAAC","sourcesContent":["import { Substitute, SubstituteOf } from './Substitute';\r\n\r\nexport { Arg } from './Arguments';\r\nexport { Substitute, SubstituteOf };\r\n\r\nexport default Substitute;"]} \ No newline at end of file diff --git a/dist/src/states/GetPropertyState.js.map b/dist/src/states/GetPropertyState.js.map index dcf7673..d76ee55 100644 --- a/dist/src/states/GetPropertyState.js.map +++ b/dist/src/states/GetPropertyState.js.map @@ -1 +1 @@ -{"version":3,"file":"GetPropertyState.js","sourceRoot":"","sources":["../../../src/states/GetPropertyState.ts"],"names":[],"mappings":";;AAEA,iDAAgD;AAIhD,IAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAEzB;IAuBI,0BAAoB,SAAsB;QAAtB,cAAS,GAAT,SAAS,CAAa;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;IApBD,sBAAY,wCAAU;aAAtB;YACI,OAAO,CAAC,CAAC,IAAI,CAAC,cAAc,CAAA;QAChC,CAAC;;;OAAA;IAED,sBAAW,sCAAQ;aAAnB;YACI,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC;;;OAAA;IAED,sBAAW,uCAAS;aAApB;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;;;OAAA;IAED,sBAAW,2CAAa;aAAxB;YACI,OAAO,IAAI,CAAC,cAAc,CAAA;QAC9B,CAAC;;;OAAA;IAQD,gCAAK,GAAL,UAAM,OAAgB,EAAE,IAAW;QAC/B,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QAEpB,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,OAAO,CAAC,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AI,CAAC,UAAU,EAAE,CAAC;gBAElB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC;YACzC,CAAC,CAAC;SACL;QAED,IAAG,CAAC,eAAe,EAAE;YACjB,IAAI,CAAC,UAAU,EAAE,CAAC;YAElB,IAAG,IAAI,CAAC,OAAO;gBACX,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE5C,IAAG,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE;gBACzB,IAAI,YAAY,GAAG,IAAI,CAAC,OAAgB,CAAC;gBACzC,IAAG,YAAY,CAAC,MAAM,KAAK,CAAC;oBACxB,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;gBAE3B,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,GAAC,CAAC,CAAC,CAAC;aAC1C;SACJ;QAED,OAAO,CAAC,YAAY,CAAC,kCAAkC,CACnD,CAAC,EAAE,CAAC,EAAG,8CAA8C;QACrD,IAAI,CAAC,SAAS,EACd,UAAU,EACV,IAAI,CAAC,QAAQ,EACb,EAAE,CAAC,CAAC;QAER,OAAO,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IACL,uBAAC;AAAD,CAAC,AArGD,IAqGC;AArGY,4CAAgB","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\nimport { Context } from \"src/Context\";\nimport { FunctionState } from \"./FunctionState\";\nimport { areArgumentsEqual, areArgumentArraysEqual } from \"../Utilities\";\nimport { Arg } from \"../Arguments\";\n\nconst Nothing = Symbol();\n\nexport class GetPropertyState implements ContextState {\n private returns: any[]|Symbol;\n private mimicks: Function|null;\n\n private _callCount: number;\n private _functionState?: FunctionState;\n\n private get isFunction(): boolean {\n return !!this._functionState\n }\n\n public get property() {\n return this._property;\n }\n\n public get callCount() {\n return this._callCount;\n }\n\n public get functionState(): FunctionState | undefined {\n return this._functionState\n }\n\n constructor(private _property: PropertyKey) {\n this.returns = Nothing;\n this.mimicks = null;\n this._callCount = 0;\n }\n\n apply(context: Context, args: any[]) {\n this._callCount = 0;\n\n if (this.functionState) {\n context.state = this.functionState\n return this.functionState.apply(context, args);\n }\n\n var functionState = new FunctionState(this);\n context.state = functionState;\n this._functionState = functionState\n\n return context.apply(args);\n }\n\n set(context: Context, property: PropertyKey, value: any) {\n }\n\n get(context: Context, property: PropertyKey) {\n const hasExpectations = context.initialState.hasExpectations;\n\n if (property === 'then')\n return void 0;\n\n if(this.isFunction)\n return context.proxy;\n\n if(property === 'mimicks') {\n return (input: Function) => {\n this.mimicks = input;\n this._callCount--;\n\n context.state = context.initialState;\n }\n }\n\n if(property === 'returns') {\n if(this.returns !== Nothing)\n throw new Error('The return value for the property ' + this._property.toString() + ' has already been set to ' + this.returns);\n\n return (...returns: any[]) => {\n this.returns = returns;\n this._callCount--;\n\n context.state = context.initialState;\n };\n }\n\n if(!hasExpectations) {\n this._callCount++;\n\n if(this.mimicks)\n return this.mimicks.apply(this.mimicks);\n\n if(this.returns !== Nothing) {\n var returnsArray = this.returns as any[];\n if(returnsArray.length === 1)\n return returnsArray[0];\n \n return returnsArray[this._callCount-1];\n }\n }\n\n context.initialState.assertCallCountMatchesExpectations(\n [[]], // I'm not sure what this was supposed to mean\n this.callCount,\n 'property',\n this.property,\n []);\n\n return context.proxy;\n }\n}"]} \ No newline at end of file +{"version":3,"file":"GetPropertyState.js","sourceRoot":"","sources":["../../../src/states/GetPropertyState.ts"],"names":[],"mappings":";;AAEA,iDAAgD;AAIhD,IAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAEzB;IAuBI,0BAAoB,SAAsB;QAAtB,cAAS,GAAT,SAAS,CAAa;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;IApBD,sBAAY,wCAAU;aAAtB;YACI,OAAO,CAAC,CAAC,IAAI,C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","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\r\nimport { Context } from \"src/Context\";\r\nimport { FunctionState } from \"./FunctionState\";\r\nimport { areArgumentsEqual, areArgumentArraysEqual } from \"../Utilities\";\r\nimport { Arg } from \"../Arguments\";\r\n\r\nconst Nothing = Symbol();\r\n\r\nexport class GetPropertyState implements ContextState {\r\n private returns: any[]|Symbol;\r\n private mimicks: Function|null;\r\n\r\n private _callCount: number;\r\n private _functionState?: FunctionState;\r\n\r\n private get isFunction(): boolean {\r\n return !!this._functionState\r\n }\r\n\r\n public get property() {\r\n return this._property;\r\n }\r\n\r\n public get callCount() {\r\n return this._callCount;\r\n }\r\n\r\n public get functionState(): FunctionState | undefined {\r\n return this._functionState\r\n }\r\n\r\n constructor(private _property: PropertyKey) {\r\n this.returns = Nothing;\r\n this.mimicks = null;\r\n this._callCount = 0;\r\n }\r\n\r\n apply(context: Context, args: any[]) {\r\n this._callCount = 0;\r\n\r\n if (this.functionState) {\r\n context.state = this.functionState\r\n return this.functionState.apply(context, args);\r\n }\r\n\r\n var functionState = new FunctionState(this);\r\n context.state = functionState;\r\n this._functionState = functionState\r\n\r\n return context.apply(args);\r\n }\r\n\r\n set(context: Context, property: PropertyKey, value: any) {\r\n }\r\n\r\n get(context: Context, property: PropertyKey) {\r\n const hasExpectations = context.initialState.hasExpectations;\r\n\r\n if (property === 'then')\r\n return void 0;\r\n\r\n if(this.isFunction)\r\n return context.proxy;\r\n\r\n if(property === 'mimicks') {\r\n return (input: Function) => {\r\n this.mimicks = input;\r\n this._callCount--;\r\n\r\n context.state = context.initialState;\r\n }\r\n }\r\n\r\n if(property === 'returns') {\r\n if(this.returns !== Nothing)\r\n throw new Error('The return value for the property ' + this._property.toString() + ' has already been set to ' + this.returns);\r\n\r\n return (...returns: any[]) => {\r\n this.returns = returns;\r\n this._callCount--;\r\n\r\n context.state = context.initialState;\r\n };\r\n }\r\n\r\n if(!hasExpectations) {\r\n this._callCount++;\r\n\r\n if(this.mimicks)\r\n return this.mimicks.apply(this.mimicks);\r\n\r\n if(this.returns !== Nothing) {\r\n var returnsArray = this.returns as any[];\r\n if(returnsArray.length === 1)\r\n return returnsArray[0];\r\n \r\n return returnsArray[this._callCount-1];\r\n }\r\n }\r\n\r\n context.initialState.assertCallCountMatchesExpectations(\r\n [[]], // I'm not sure what this was supposed to mean\r\n this.callCount,\r\n 'property',\r\n this.property,\r\n []);\r\n\r\n return context.proxy;\r\n }\r\n}"]} \ No newline at end of file diff --git a/dist/src/states/SetPropertyState.js.map b/dist/src/states/SetPropertyState.js.map index 03b2854..c6727bb 100644 --- a/dist/src/states/SetPropertyState.js.map +++ b/dist/src/states/SetPropertyState.js.map @@ -1 +1 @@ -{"version":3,"file":"SetPropertyState.js","sourceRoot":"","sources":["../../../src/states/SetPropertyState.ts"],"names":[],"mappings":";;AAEA,0CAAqE;AAErE,IAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAEzB;IAgBI,0BAAoB,SAAsB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAAtC,cAAS,GAAT,SAAS,CAAa;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;IAhBD,sBAAW,uCAAS;aAApB;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;;;OAAA;IAED,sBAAW,sCAAQ;aAAnB;YACI,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC;;;OAAA;IAED,sBAAW,uCAAS;aAApB;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;;;OAAA;IAQD,gCAAK,GAAL,UAAM,OAAgB;QAClB,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,8BAAG,GAAH,UAAI,OAAgB,EAAE,QAAqB,EAAE,KAAU;QACnD,IAAI,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAChC,IAAM,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC;QAC7D,IAAG,eAAe,EAAE;YAChB,SAAS,GAAG,OAAO,CAAC,YAAY;iBAC3B,iBAAiB;iBACjB,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,6BAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAxC,CAAwC,CAAC;iBACrD,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,EAAZ,CAAY,CAAC;iBACtB,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC;SACnC;QAED,OAAO,CAAC,YAAY,CAAC,kCAAkC,CACnD,CAAC,EAAE,CAAC,EAAE,wCAAwC;QAC9C,SAAS,EACT,UAAU,EACV,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,CAAC,CAAC;QAEpB,IAAG,CAAC,eAAe,EAAE;YACjB,IAAI,CAAC,UAAU,EAAE,CAAC;SACrB;IACL,CAAC;IAED,8BAAG,GAAH,UAAI,OAAgB,EAAE,QAAqB;QACvC,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;IACL,uBAAC;AAAD,CAAC,AApDD,IAoDC;AApDY,4CAAgB","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\nimport { Context } from \"src/Context\";\nimport { stringifyArguments, areArgumentsEqual } from \"../Utilities\";\n\nconst Nothing = Symbol();\n\nexport class SetPropertyState implements ContextState {\n private _callCount: number;\n private _arguments: any[];\n\n public get arguments() {\n return this._arguments;\n }\n\n public get property() {\n return this._property;\n }\n\n public get callCount() {\n return this._callCount;\n }\n\n constructor(private _property: PropertyKey, ...args: any[]) {\n this._arguments = args;\n\n this._callCount = 0;\n }\n\n apply(context: Context): undefined {\n return void 0;\n }\n\n set(context: Context, property: PropertyKey, value: any) {\n let callCount = this._callCount;\n const hasExpectations = context.initialState.hasExpectations;\n if(hasExpectations) {\n callCount = context.initialState\n .setPropertyStates\n .filter(x => areArgumentsEqual(x.arguments[0], value))\n .map(x => x._callCount)\n .reduce((a, b) => a + b, 0);\n }\n\n context.initialState.assertCallCountMatchesExpectations(\n [[]], // not sure what this was supposed to do\n callCount,\n 'property',\n this.property,\n this.arguments);\n\n if(!hasExpectations) {\n this._callCount++;\n }\n }\n\n get(context: Context, property: PropertyKey): undefined {\n return void 0;\n }\n}"]} \ No newline at end of file +{"version":3,"file":"SetPropertyState.js","sourceRoot":"","sources":["../../../src/states/SetPropertyState.ts"],"names":[],"mappings":";;AAEA,0CAAqE;AAErE,IAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAEzB;IAgBI,0BAAoB,SAAsB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QAAtC,cAAS,GAAT,SAAS,CAAa;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;IAhBD,sBAAW,uCAAS;aAApB;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;;;OAAA;IAED,sBAAW,sCAAQ;aAAnB;YACI,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC;;;OAAA;IAED,sBAAW,uCAAS;aAApB;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;;;OAAA;IAQD,gCAAK,GAAL,UAAM,OAAgB;QAClB,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,8BAAG,GAAH,UAAI,OAAgB,EAAE,QAAqB,EAAE,KAAU;QACnD,IAAI,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAChC,IAAM,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC;QAC7D,IAAG,eAAe,EAAE;YAChB,SAAS,GAAG,OAAO,CAAC,YAAY;iBAC3B,iBAAiB;iBACjB,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,6BAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAxC,CAAwC,CAAC;iBACrD,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,EAAZ,CAAY,CAAC;iBACtB,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC;SACnC;QAED,OAAO,CAAC,YAAY,CAAC,kCAAkC,CACnD,CAAC,EAAE,CAAC,EAAE,wCAAwC;QAC9C,SAAS,EACT,UAAU,EACV,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,CAAC,CAAC;QAEpB,IAAG,CAAC,eAAe,EAAE;YACjB,IAAI,CAAC,UAAU,EAAE,CAAC;SACrB;IACL,CAAC;IAED,8BAAG,GAAH,UAAI,OAAgB,EAAE,QAAqB;QACvC,OAAO,KAAK,CAAC,CAAC;IAClB,CAAC;IACL,uBAAC;AAAD,CAAC,AApDD,IAoDC;AApDY,4CAAgB","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\r\nimport { Context } from \"src/Context\";\r\nimport { stringifyArguments, areArgumentsEqual } from \"../Utilities\";\r\n\r\nconst Nothing = Symbol();\r\n\r\nexport class SetPropertyState implements ContextState {\r\n private _callCount: number;\r\n private _arguments: any[];\r\n\r\n public get arguments() {\r\n return this._arguments;\r\n }\r\n\r\n public get property() {\r\n return this._property;\r\n }\r\n\r\n public get callCount() {\r\n return this._callCount;\r\n }\r\n\r\n constructor(private _property: PropertyKey, ...args: any[]) {\r\n this._arguments = args;\r\n\r\n this._callCount = 0;\r\n }\r\n\r\n apply(context: Context): undefined {\r\n return void 0;\r\n }\r\n\r\n set(context: Context, property: PropertyKey, value: any) {\r\n let callCount = this._callCount;\r\n const hasExpectations = context.initialState.hasExpectations;\r\n if(hasExpectations) {\r\n callCount = context.initialState\r\n .setPropertyStates\r\n .filter(x => areArgumentsEqual(x.arguments[0], value))\r\n .map(x => x._callCount)\r\n .reduce((a, b) => a + b, 0);\r\n }\r\n\r\n context.initialState.assertCallCountMatchesExpectations(\r\n [[]], // not sure what this was supposed to do\r\n callCount,\r\n 'property',\r\n this.property,\r\n this.arguments);\r\n\r\n if(!hasExpectations) {\r\n this._callCount++;\r\n }\r\n }\r\n\r\n get(context: Context, property: PropertyKey): undefined {\r\n return void 0;\r\n }\r\n}"]} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7c34132..31db5b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -399,9 +399,9 @@ } }, "@types/node": { - "version": "11.9.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.9.5.tgz", - "integrity": "sha512-vVjM0SVzgaOUpflq4GYBvCpozes8OgIIS5gVXVka+OfK3hvnkC1i93U8WiY2OtNE4XUWyyy/86Kf6e0IHTQw1Q==", + "version": "11.12.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-11.12.1.tgz", + "integrity": "sha512-sKDlqv6COJrR7ar0+GqqhrXQDzQlMcqMnF2iEU6m9hLo8kxozoAGUazwPyELHlRVmjsbvlnGXjnzyptSXVmceA==", "dev": true }, "ansi-align": { @@ -1645,7 +1645,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2060,7 +2061,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2116,6 +2118,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2159,12 +2162,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/src/Substitute.ts b/src/Substitute.ts index 5f90250..57af473 100644 --- a/src/Substitute.ts +++ b/src/Substitute.ts @@ -4,8 +4,10 @@ import { ObjectSubstitute, OmitProxyMethods, DisabledSubstituteObject } from "./ export const HandlerKey = Symbol(); export const AreProxiesDisabledKey = Symbol(); +export type SubstituteOf = ObjectSubstitute, T> & T; + export class Substitute { - static for(): ObjectSubstitute, T> & T { + static for(): SubstituteOf { const objectContext = new Context(); return objectContext.rootProxy; } diff --git a/src/index.ts b/src/index.ts index 33d5be1..2177c84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import { Substitute } from './Substitute'; +import { Substitute, SubstituteOf } from './Substitute'; export { Arg } from './Arguments'; -export { Substitute }; +export { Substitute, SubstituteOf }; export default Substitute; \ No newline at end of file