diff --git a/.gitignore b/.gitignore index 3e759b7..ee295b7 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,8 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +# Build +dist/ +fluffy-spoon-substitute-*.tgz +package/ diff --git a/dist/spec/Utilities.spec.d.ts b/dist/spec/Utilities.spec.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/Utilities.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/Utilities.spec.js b/dist/spec/Utilities.spec.js deleted file mode 100644 index 934b55f..0000000 --- a/dist/spec/Utilities.spec.js +++ /dev/null @@ -1,77 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var Utilities_1 = require("../src/Utilities"); -var index_1 = require("../src/index"); -var testObject = { "foo": "bar" }; -var testArray = ["a", 1, true]; -var testFunc = function () { }; -//#region areArgumentArraysEqual -ava_1.default('areArgumentArraysEqual should return valid result for primitive arguments', function (t) { - // single - t.true(Utilities_1.areArgumentArraysEqual([''], [''])); - t.true(Utilities_1.areArgumentArraysEqual(['a'], ['a'])); - t.true(Utilities_1.areArgumentArraysEqual([0], [0])); - t.true(Utilities_1.areArgumentArraysEqual([1], [1])); - t.true(Utilities_1.areArgumentArraysEqual([true], [true])); - t.true(Utilities_1.areArgumentArraysEqual([false], [false])); - t.true(Utilities_1.areArgumentArraysEqual([undefined], [undefined])); - t.true(Utilities_1.areArgumentArraysEqual([null], [null])); - t.true(Utilities_1.areArgumentArraysEqual([testObject], [testObject])); - t.true(Utilities_1.areArgumentArraysEqual([testArray], [testArray])); - t.true(Utilities_1.areArgumentArraysEqual([testFunc], [testFunc])); - t.false(Utilities_1.areArgumentArraysEqual(['a'], ['b'])); - t.false(Utilities_1.areArgumentArraysEqual([1], [2])); - t.false(Utilities_1.areArgumentArraysEqual([true], [false])); - t.false(Utilities_1.areArgumentArraysEqual([undefined], [null])); - t.false(Utilities_1.areArgumentArraysEqual([testObject], [testArray])); - // multi - t.true(Utilities_1.areArgumentArraysEqual([1, 2, 3], [1, 2, 3])); - t.false(Utilities_1.areArgumentArraysEqual([1, 2, 3], [3, 2, 1])); - t.false(Utilities_1.areArgumentArraysEqual([1, 2, 3, 4], [1, 2, 3])); - t.false(Utilities_1.areArgumentArraysEqual([1, 2, 3], [1, 2, 3, 4])); -}); -ava_1.default('areArgumentArraysEqual should return valid result using Arg.all()', function (t) { - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [0])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [1])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], ['string'])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [true])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [false])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [null])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [undefined])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], [1, 2])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.all()], ['string1', 'string2'])); -}); -ava_1.default('areArgumentArraysEqual should return valid result using Arg.any()', function (t) { - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], ['hi'])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [1])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [0])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [false])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [true])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [null])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [undefined])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [testObject])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [testArray])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [testFunc])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any()], [])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('string')], ['foo'])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('number')], [1])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('boolean')], [true])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('object')], [testObject])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('array')], [testArray])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('function')], [testFunc])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('string')], [1])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('number')], ['string'])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('boolean')], [null])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('object')], ['foo'])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('array')], ['bar'])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.any('function')], ['foo'])); -}); -ava_1.default('areArgumentArraysEqual should return valid result using Arg.is()', function (t) { - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.is(function (x) { return x === 'foo'; })], ['foo'])); - t.true(Utilities_1.areArgumentArraysEqual([index_1.Arg.is(function (x) { return x % 2 == 0; })], [4])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.is(function (x) { return x === 'foo'; })], ['bar'])); - t.false(Utilities_1.areArgumentArraysEqual([index_1.Arg.is(function (x) { return x % 2 == 0; })], [3])); -}); -//# sourceMappingURL=Utilities.spec.js.map \ No newline at end of file diff --git a/dist/spec/Utilities.spec.js.map b/dist/spec/Utilities.spec.js.map deleted file mode 100644 index a5a3040..0000000 --- a/dist/spec/Utilities.spec.js.map +++ /dev/null @@ -1 +0,0 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A,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,IAAI,CAAC,EAAV,CAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/D,CAAC,CAAC,KAAK,CAAC,kCAAsB,CAAC,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,KAAK,KAAK,EAAX,CAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC,KAAK,CAAC,kCAAsB,CAAC,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,IAAI,CAAC,EAAV,CAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\nimport { areArgumentArraysEqual } from '../src/Utilities';\r\nimport { Arg } from '../src/index';\r\n\r\nconst testObject = { \"foo\": \"bar\" };\r\nconst testArray = [\"a\", 1, true];\r\nconst testFunc = () => {};\r\n\r\n//#region areArgumentArraysEqual\r\ntest('areArgumentArraysEqual should return valid result for primitive arguments', t => {\r\n // single \r\n t.true(areArgumentArraysEqual([''],['']));\r\n t.true(areArgumentArraysEqual(['a'],['a']));\r\n t.true(areArgumentArraysEqual([0],[0]));\r\n t.true(areArgumentArraysEqual([1],[1]));\r\n t.true(areArgumentArraysEqual([true],[true]));\r\n t.true(areArgumentArraysEqual([false],[false]));\r\n t.true(areArgumentArraysEqual([undefined],[undefined]));\r\n t.true(areArgumentArraysEqual([null],[null]));\r\n t.true(areArgumentArraysEqual([testObject],[testObject]));\r\n t.true(areArgumentArraysEqual([testArray],[testArray]));\r\n t.true(areArgumentArraysEqual([testFunc],[testFunc]));\r\n\r\n t.false(areArgumentArraysEqual(['a'],['b']));\r\n t.false(areArgumentArraysEqual([1],[2]));\r\n t.false(areArgumentArraysEqual([true],[false]));\r\n t.false(areArgumentArraysEqual([undefined],[null]));\r\n t.false(areArgumentArraysEqual([testObject],[testArray]));\r\n\r\n // multi\r\n t.true(areArgumentArraysEqual([1,2,3], [1,2,3]));\r\n\r\n t.false(areArgumentArraysEqual([1,2,3], [3,2,1]));\r\n t.false(areArgumentArraysEqual([1,2,3,4], [1,2,3]));\r\n t.false(areArgumentArraysEqual([1,2,3], [1,2,3,4])); \r\n})\r\n\r\ntest('areArgumentArraysEqual should return valid result using Arg.all()', t => {\r\n t.true(areArgumentArraysEqual([Arg.all()],[]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[0]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[1]));\r\n t.true(areArgumentArraysEqual([Arg.all()],['string']));\r\n t.true(areArgumentArraysEqual([Arg.all()],[true]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[false]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[null]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[undefined]));\r\n t.true(areArgumentArraysEqual([Arg.all()],[1,2]));\r\n t.true(areArgumentArraysEqual([Arg.all()],['string1', 'string2']));\r\n})\r\n\r\ntest('areArgumentArraysEqual should return valid result using Arg.any()', t => {\r\n t.true(areArgumentArraysEqual([Arg.any()], ['hi']));\r\n t.true(areArgumentArraysEqual([Arg.any()], [1]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [0]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [false]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [true]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [null]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [undefined]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [testObject]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [testArray]));\r\n t.true(areArgumentArraysEqual([Arg.any()], [testFunc]));\r\n t.true(areArgumentArraysEqual([Arg.any()], []));\r\n\r\n t.true(areArgumentArraysEqual([Arg.any('string')], ['foo']));\r\n t.true(areArgumentArraysEqual([Arg.any('number')], [1]));\r\n t.true(areArgumentArraysEqual([Arg.any('boolean')], [true]));\r\n t.true(areArgumentArraysEqual([Arg.any('object')], [testObject]));\r\n t.true(areArgumentArraysEqual([Arg.any('array')], [testArray]));\r\n t.true(areArgumentArraysEqual([Arg.any('function')], [testFunc]));\r\n\r\n t.false(areArgumentArraysEqual([Arg.any('string')], [1]));\r\n t.false(areArgumentArraysEqual([Arg.any('number')], ['string']));\r\n t.false(areArgumentArraysEqual([Arg.any('boolean')], [null]));\r\n t.false(areArgumentArraysEqual([Arg.any('object')], ['foo']));\r\n t.false(areArgumentArraysEqual([Arg.any('array')], ['bar']));\r\n t.false(areArgumentArraysEqual([Arg.any('function')], ['foo']));\r\n})\r\n\r\ntest('areArgumentArraysEqual should return valid result using Arg.is()', t => {\r\n t.true(areArgumentArraysEqual([Arg.is(x => x === 'foo')], ['foo']));\r\n t.true(areArgumentArraysEqual([Arg.is(x => x % 2 == 0)], [4]));\r\n\r\n t.false(areArgumentArraysEqual([Arg.is(x => x === 'foo')], ['bar']));\r\n t.false(areArgumentArraysEqual([Arg.is(x => x % 2 == 0)], [3]));\r\n});"]} \ No newline at end of file diff --git a/dist/spec/index.test.d.ts b/dist/spec/index.test.d.ts deleted file mode 100644 index b3d6261..0000000 --- a/dist/spec/index.test.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -declare class Dummy { -} -export declare class Example { - a: string; - c(arg1: string, arg2: string): string; - readonly d: number; - v: string | null | undefined; - received(stuff: number | string): void; - returnPromise(): Promise; - foo(): string | undefined | null; - bar(a: number, b?: number): number; -} -export {}; diff --git a/dist/spec/index.test.js b/dist/spec/index.test.js deleted file mode 100644 index 2ec0113..0000000 --- a/dist/spec/index.test.js +++ /dev/null @@ -1,278 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var _this = this; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../src/index"); -var Dummy = /** @class */ (function () { - function Dummy() { - } - return Dummy; -}()); -var Example = /** @class */ (function () { - function Example() { - this.a = "1337"; - } - Example.prototype.c = function (arg1, arg2) { - return "hello " + arg1 + " world (" + arg2 + ")"; - }; - Object.defineProperty(Example.prototype, "d", { - get: function () { - return 1337; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Example.prototype, "v", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - Example.prototype.received = function (stuff) { - }; - Example.prototype.returnPromise = function () { - return Promise.resolve(new Dummy()); - }; - Example.prototype.foo = function () { - return 'stuff'; - }; - Example.prototype.bar = function (a, b) { - return a + b || 0; - }; - return Example; -}()); -exports.Example = Example; -var instance; -var substitute; -function initialize() { - instance = new Example(); - substitute = index_1.Substitute.for(); -} -; -ava_1.default('can call received twice', function (t) { - initialize(); - substitute.c('blah', 'fuzz'); - t.throws(function () { return substitute.received(1337).c('foo', 'bar'); }, "Expected 1337 calls to the method c with arguments ['foo', 'bar'], but received none of such calls.\nAll calls received to method c:\n-> call with arguments ['blah', 'fuzz']"); - t.throws(function () { return substitute.received(2117).c('foo', 'bar'); }, "Expected 2117 calls to the method c with arguments ['foo', 'bar'], but received none of such calls.\nAll calls received to method c:\n-> call with arguments ['blah', 'fuzz']"); -}); -ava_1.default('class string field get returns', function (t) { - initialize(); - substitute.a.returns("foo", "bar"); - t.deepEqual(substitute.a, 'foo'); - t.deepEqual(substitute.a, 'bar'); - t.deepEqual(substitute.a, void 0); - t.deepEqual(substitute.a, void 0); -}); -ava_1.default('class with method called "received" can be used for call count verification when proxies are suspended', function (t) { - initialize(); - index_1.Substitute.disableFor(substitute).received(2); - t.throws(function () { return substitute.received(2).received(2); }); - t.notThrows(function () { return substitute.received(1).received(2); }); -}); -ava_1.default('class with method called "received" can be used for call count verification', function (t) { - initialize(); - index_1.Substitute.disableFor(substitute).received('foo'); - t.notThrows(function () { return substitute.received(1).received('foo'); }); - t.throws(function () { return substitute.received(2).received('foo'); }); -}); -ava_1.default('partial mocks using function mimicks with all args', function (t) { - initialize(); - substitute.c(index_1.Arg.all()).mimicks(instance.c); - t.deepEqual(substitute.c('a', 'b'), 'hello a world (b)'); -}); -ava_1.default('class string field get received', function (t) { - initialize(); - void substitute.a; - void substitute.a; - void substitute.a; - void substitute.a; - t.throws(function () { return substitute.received(3).a; }); - t.notThrows(function () { return substitute.received().a; }); - t.notThrows(function () { return substitute.received(4).a; }); -}); -ava_1.default('class string field set received', function (t) { - initialize(); - substitute.v = undefined; - substitute.v = null; - substitute.v = 'hello'; - substitute.v = 'hello'; - substitute.v = 'world'; - t.notThrows(function () { return substitute.received().v = 'hello'; }); - t.notThrows(function () { return substitute.received(5).v = index_1.Arg.any(); }); - t.notThrows(function () { return substitute.received().v = index_1.Arg.any(); }); - t.notThrows(function () { return substitute.received(2).v = 'hello'; }); - t.notThrows(function () { return substitute.received(2).v = index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); }); - t.throws(function () { return substitute.received(2).v = index_1.Arg.any(); }); - t.throws(function () { return substitute.received(1).v = index_1.Arg.any(); }); - t.throws(function () { return substitute.received(1).v = index_1.Arg.is(function (x) { return x && x.indexOf('ll') > -1; }); }); - t.throws(function () { return substitute.received(3).v = 'hello'; }); -}); -ava_1.default('class method returns with placeholder args', function (t) { - initialize(); - substitute.c(index_1.Arg.any(), "there").returns("blah", "haha"); - t.is(substitute.c("hi", "there"), 'blah'); - t.is(substitute.c("his", "there"), 'haha'); - t.is(substitute.c("his", "there"), void 0); - t.is(substitute.c("hi", "there"), void 0); -}); -ava_1.default('partial mocks using function mimicks with specific args', function (t) { - initialize(); - substitute.c('a', 'b').mimicks(instance.c); - t.is(substitute.c('a', 'b'), 'hello a world (b)'); -}); -ava_1.default('class method returns with specific args', function (t) { - initialize(); - substitute.c("hi", "there").returns("blah", "haha"); - t.is(substitute.c("hi", "there"), 'blah'); - t.is(substitute.c("hi", "there"), 'haha'); - t.is(substitute.c("hi", "there"), void 0); - t.is(substitute.c("hi", "there"), void 0); -}); -ava_1.default('returning other fake from promise works', function (t) { return __awaiter(_this, void 0, void 0, function () { - var otherSubstitute, _a, _b, _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - initialize(); - otherSubstitute = index_1.Substitute.for(); - substitute.returnPromise().returns(Promise.resolve(otherSubstitute)); - _b = (_a = t).is; - _c = [otherSubstitute]; - return [4 /*yield*/, substitute.returnPromise()]; - case 1: - _b.apply(_a, _c.concat([_d.sent()])); - return [2 /*return*/]; - } - }); -}); }); -ava_1.default('returning resolved promises works', function (t) { return __awaiter(_this, void 0, void 0, function () { - var _a, _b, _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - initialize(); - substitute.returnPromise().returns(Promise.resolve(1338)); - _b = (_a = t).is; - _c = [1338]; - return [4 /*yield*/, substitute.returnPromise()]; - case 1: - _b.apply(_a, _c.concat([_d.sent()])); - return [2 /*return*/]; - } - }); -}); }); -ava_1.default('class void returns', function (t) { - initialize(); - substitute.foo().returns(void 0, null); - t.is(substitute.foo(), void 0); - t.is(substitute.foo(), null); -}); -ava_1.default('class method received', function (t) { - initialize(); - void substitute.c("hi", "there"); - void substitute.c("hi", "the1re"); - void substitute.c("hi", "there"); - void substitute.c("hi", "there"); - void substitute.c("hi", "there"); - t.notThrows(function () { return substitute.received(4).c('hi', 'there'); }); - t.notThrows(function () { return substitute.received(1).c('hi', 'the1re'); }); - t.notThrows(function () { return substitute.received().c('hi', 'there'); }); - t.throws(function () { return substitute.received(7).c('hi', 'there'); }, "Expected 7 calls to the method c with arguments ['hi', 'there'], but received 4 of such calls.\nAll calls received to method c:\n-> call with arguments ['hi', 'there']\n-> call with arguments ['hi', 'the1re']\n-> call with arguments ['hi', 'there']\n-> call with arguments ['hi', 'there']\n-> call with arguments ['hi', 'there']"); -}); -ava_1.default('received call matches after partial mocks using property instance mimicks', function (t) { - initialize(); - substitute.d.mimicks(function () { return instance.d; }); - substitute.c('lala', 'bar'); - substitute.received(1).c('lala', 'bar'); - substitute.received(1).c('lala', 'bar'); - t.notThrows(function () { return substitute.received(1).c('lala', 'bar'); }); - t.throws(function () { return substitute.received(2).c('lala', 'bar'); }, "Expected 2 calls to the method c with arguments ['lala', 'bar'], but received 1 of such call.\nAll calls received to method c:\n-> call with arguments ['lala', 'bar']"); - t.deepEqual(substitute.d, 1337); -}); -ava_1.default('partial mocks using property instance mimicks', function (t) { - initialize(); - substitute.d.mimicks(function () { return instance.d; }); - t.deepEqual(substitute.d, 1337); -}); -ava_1.default('verifying with more arguments fails', function (t) { - initialize(); - substitute.bar(1); - substitute.received().bar(1); - t.throws(function () { return substitute.received().bar(1, 2); }); -}); -ava_1.default('verifying with less arguments fails', function (t) { - initialize(); - substitute.bar(1, 2); - substitute.received().bar(1, 2); - t.throws(function () { return substitute.received().bar(1); }); -}); -ava_1.default('return with more arguments is not matched fails', function (t) { - initialize(); - substitute.bar(1, 2).returns(3); - t.is(3, substitute.bar(1, 2)); - t.is('function', typeof (substitute.bar(1))); -}); -ava_1.default('return with less arguments is not matched', function (t) { - initialize(); - substitute.bar(1).returns(3); - t.is(3, substitute.bar(1)); - t.is('function', typeof (substitute.bar(1, 2).toString)); -}); -ava_1.default('can stub multiple primitive return values', function (t) { - initialize(); - substitute.bar(1).returns(2); - substitute.bar(2).returns(3); - t.is(2, substitute.bar(1)); - t.is(3, substitute.bar(2)); -}); -ava_1.default('can stub multiple Arg values', function (t) { - initialize(); - substitute.bar(index_1.Arg.is(function (x) { return x % 2 === 0; })).returns(1); - substitute.bar(index_1.Arg.is(function (x) { return x % 2 !== 0; })).returns(2); - t.is(1, substitute.bar(4)); - t.is(2, substitute.bar(5)); -}); -ava_1.default.skip('can stub primitive & Arg values', function (t) { - initialize(); - substitute.bar(1).returns(2); - substitute.bar(index_1.Arg.any()).returns(3); // throws 'substitute.bar(...).returns is not a function' - t.is(5, substitute.bar(2)); - t.is(2, substitute.bar(1)); - t.is(3, substitute.bar(2)); -}); -//# sourceMappingURL=index.test.js.map \ No newline at end of file diff --git a/dist/spec/index.test.js.map b/dist/spec/index.test.js.map deleted file mode 100644 index ed1c93f..0000000 --- a/dist/spec/index.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.test.js","sourceRoot":"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C,GAAG,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACnD,UAAU,CAAC,GAAG,CAAC,WAAG,CAAC,EAAE,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,KAAK,CAAC,EAAX,CAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACnD,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAC,CAAA;AAGF,aAAI,CAAC,IAAI,CAAC,iCAAiC,EAAE,UAAA,CAAC;IAC1C,UAAU,EAAE,CAAA;IACZ,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC5B,UAAU,CAAC,GAAG,CAAC,WAAG,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA,CAAC,yDAAyD;IAC9F,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAC,CAAA","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute, Arg } from '../src/index';\r\nimport { OmitProxyMethods, ObjectSubstitute } from '../src/Transformations';\r\n\r\nclass Dummy {\r\n\r\n}\r\n\r\nexport class Example {\r\n\ta = \"1337\";\r\n\r\n\tc(arg1: string, arg2: string) {\r\n\t\treturn \"hello \" + arg1 + \" world (\" + arg2 + \")\";\r\n\t}\r\n\r\n\tget d() {\r\n\t\treturn 1337;\r\n\t}\r\n\r\n\tset v(x: string|null|undefined) {\r\n\t}\r\n\r\n\treceived(stuff: number|string) {\r\n\r\n\t}\r\n\r\n\treturnPromise() {\r\n\t\treturn Promise.resolve(new Dummy());\r\n\t}\r\n\r\n\tfoo(): string|undefined|null {\r\n\t\treturn 'stuff';\r\n }\r\n \r\n bar (a: number, b?: number): number{\r\n return a + b || 0\r\n }\r\n}\r\n\r\nlet instance: Example;\r\nlet substitute: ObjectSubstitute, Example>;\r\n\r\nfunction initialize() {\r\n\tinstance = new Example();\r\n\tsubstitute = Substitute.for();\r\n};\r\n\r\ntest('can call received twice', t => { \r\n\tinitialize();\r\n\r\n\tsubstitute.c('blah', 'fuzz');\r\n\r\n\tt.throws(() => substitute.received(1337).c('foo', 'bar'), \r\n`Expected 1337 calls to the method c with arguments ['foo', 'bar'], but received none of such calls.\r\nAll calls received to method c:\r\n-> call with arguments ['blah', 'fuzz']`);\r\n\r\n\tt.throws(() => substitute.received(2117).c('foo', 'bar'),\r\n`Expected 2117 calls to the method c with arguments ['foo', 'bar'], but received none of such calls.\r\nAll calls received to method c:\r\n-> call with arguments ['blah', 'fuzz']`);\r\n});\r\n\r\ntest('class string field get returns', t => {\r\n\tinitialize();\r\n\r\n\tsubstitute.a.returns(\"foo\", \"bar\");\r\n\r\n\tt.deepEqual(substitute.a, 'foo');\r\n\tt.deepEqual(substitute.a, 'bar');\r\n\tt.deepEqual(substitute.a, void 0);\r\n\tt.deepEqual(substitute.a, void 0);\r\n});\r\n\r\ntest('class with method called \"received\" can be used for call count verification when proxies are suspended', t => {\r\n\tinitialize();\r\n\t\r\n\tSubstitute.disableFor(substitute).received(2);\r\n\r\n\tt.throws(() => substitute.received(2).received(2));\r\n\tt.notThrows(() => substitute.received(1).received(2));\r\n});\r\n\r\ntest('class with method called \"received\" can be used for call count verification', t => {\r\n\tinitialize();\r\n\t\r\n\tSubstitute.disableFor(substitute).received('foo');\r\n\r\n\tt.notThrows(() => substitute.received(1).received('foo'));\r\n\tt.throws(() => substitute.received(2).received('foo'));\r\n});\r\n\r\ntest('partial mocks using function mimicks with all args', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.c(Arg.all()).mimicks(instance.c);\r\n\r\n\tt.deepEqual(substitute.c('a', 'b'), 'hello a world (b)');\r\n});\r\n\r\ntest('class string field get received', t => {\r\n\tinitialize();\r\n\t\r\n\tvoid substitute.a;\r\n\tvoid substitute.a;\r\n\tvoid substitute.a;\r\n\tvoid substitute.a;\r\n\r\n\tt.throws(() => substitute.received(3).a);\r\n\tt.notThrows(() => substitute.received().a);\r\n\tt.notThrows(() => substitute.received(4).a);\r\n});\r\n\r\ntest('class string field set received', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.v = undefined;\r\n\tsubstitute.v = null;\r\n\tsubstitute.v = 'hello';\r\n\tsubstitute.v = 'hello';\r\n\tsubstitute.v = 'world';\r\n\t\r\n\tt.notThrows(() => substitute.received().v = 'hello');\r\n\tt.notThrows(() => substitute.received(5).v = Arg.any());\r\n\tt.notThrows(() => substitute.received().v = Arg.any());\r\n\tt.notThrows(() => substitute.received(2).v = 'hello');\r\n\tt.notThrows(() => substitute.received(2).v = Arg.is(x => x && x.indexOf('ll') > -1));\r\n\r\n\tt.throws(() => substitute.received(2).v = Arg.any());\r\n\tt.throws(() => substitute.received(1).v = Arg.any());\r\n\tt.throws(() => substitute.received(1).v = Arg.is(x => x && x.indexOf('ll') > -1));\r\n\tt.throws(() => substitute.received(3).v = 'hello');\r\n});\r\n\r\ntest('class method returns with placeholder args', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.c(Arg.any(), \"there\").returns(\"blah\", \"haha\");\r\n\t\r\n\tt.is(substitute.c(\"hi\", \"there\"), 'blah');\r\n\tt.is(substitute.c(\"his\", \"there\"), 'haha');\r\n\tt.is(substitute.c(\"his\", \"there\"), void 0);\r\n\tt.is(substitute.c(\"hi\", \"there\"), void 0);\r\n});\r\n\r\ntest('partial mocks using function mimicks with specific args', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.c('a', 'b').mimicks(instance.c);\r\n\r\n\tt.is(substitute.c('a', 'b'), 'hello a world (b)');\r\n});\r\n\r\ntest('class method returns with specific args', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.c(\"hi\", \"there\").returns(\"blah\", \"haha\");\r\n\r\n\tt.is(substitute.c(\"hi\", \"there\"), 'blah');\r\n\tt.is(substitute.c(\"hi\", \"there\"), 'haha');\r\n\tt.is(substitute.c(\"hi\", \"there\"), void 0);\r\n\tt.is(substitute.c(\"hi\", \"there\"), void 0);\r\n});\r\n\r\ntest('returning other fake from promise works', async t => {\r\n\tinitialize();\r\n\t\r\n\tconst otherSubstitute = Substitute.for();\r\n\tsubstitute.returnPromise().returns(Promise.resolve(otherSubstitute));\r\n t.is(otherSubstitute, await substitute.returnPromise());\r\n});\r\n\r\ntest('returning resolved promises works', async t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.returnPromise().returns(Promise.resolve(1338));\r\n\r\n\tt.is(1338, await substitute.returnPromise());\r\n});\r\n\r\ntest('class void returns', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.foo().returns(void 0, null);\r\n\r\n\tt.is(substitute.foo(), void 0);\r\n\tt.is(substitute.foo(), null);\r\n}); \r\n\r\ntest('class method received', t => {\r\n\tinitialize();\r\n\t\r\n\tvoid substitute.c(\"hi\", \"there\");\r\n\tvoid substitute.c(\"hi\", \"the1re\");\r\n\tvoid substitute.c(\"hi\", \"there\");\r\n\tvoid substitute.c(\"hi\", \"there\");\r\n\tvoid substitute.c(\"hi\", \"there\");\r\n\r\n\tt.notThrows(() => substitute.received(4).c('hi', 'there'));\r\n\tt.notThrows(() => substitute.received(1).c('hi', 'the1re'));\r\n\tt.notThrows(() => substitute.received().c('hi', 'there'));\r\n\r\n\tt.throws(() => substitute.received(7).c('hi', 'there'), \r\n`Expected 7 calls to the method c with arguments ['hi', 'there'], but received 4 of such calls.\r\nAll calls received to method c:\r\n-> call with arguments ['hi', 'there']\r\n-> call with arguments ['hi', 'the1re']\r\n-> call with arguments ['hi', 'there']\r\n-> call with arguments ['hi', 'there']\r\n-> call with arguments ['hi', 'there']`);\r\n});\r\n\r\ntest('received call matches after partial mocks using property instance mimicks', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.d.mimicks(() => instance.d);\r\n\tsubstitute.c('lala', 'bar');\r\n\r\n\tsubstitute.received(1).c('lala', 'bar');\r\n\tsubstitute.received(1).c('lala', 'bar');\r\n\r\n\tt.notThrows(() => substitute.received(1).c('lala', 'bar'));\r\n\tt.throws(() => substitute.received(2).c('lala', 'bar'),\r\n`Expected 2 calls to the method c with arguments ['lala', 'bar'], but received 1 of such call.\r\nAll calls received to method c:\r\n-> call with arguments ['lala', 'bar']`);\r\n\t\r\n\tt.deepEqual(substitute.d, 1337);\r\n});\r\n\r\ntest('partial mocks using property instance mimicks', t => {\r\n\tinitialize();\r\n\t\r\n\tsubstitute.d.mimicks(() => instance.d);\r\n\r\n\tt.deepEqual(substitute.d, 1337);\r\n});\r\n\r\ntest('verifying with more arguments fails', t => {\r\n initialize()\r\n substitute.bar(1)\r\n substitute.received().bar(1)\r\n t.throws(() => substitute.received().bar(1, 2))\r\n})\r\n\r\ntest('verifying with less arguments fails', t => {\r\n initialize()\r\n substitute.bar(1, 2)\r\n substitute.received().bar(1, 2)\r\n t.throws(() => substitute.received().bar(1))\r\n})\r\n\r\ntest('return with more arguments is not matched fails', t => {\r\n initialize()\r\n substitute.bar(1, 2).returns(3)\r\n t.is(3, substitute.bar(1, 2))\r\n t.is('function', typeof(substitute.bar(1)))\r\n})\r\n\r\ntest('return with less arguments is not matched', t => {\r\n initialize()\r\n substitute.bar(1).returns(3)\r\n t.is(3, substitute.bar(1))\r\n t.is('function', typeof(substitute.bar(1, 2).toString))\r\n})\r\n\r\ntest('can stub multiple primitive return values', t => {\r\n initialize()\r\n substitute.bar(1).returns(2)\r\n substitute.bar(2).returns(3)\r\n t.is(2, substitute.bar(1))\r\n t.is(3, substitute.bar(2))\r\n})\r\n\r\ntest('can stub multiple Arg values', t => {\r\n initialize()\r\n substitute.bar(Arg.is(x => x % 2 === 0)).returns(1)\r\n substitute.bar(Arg.is(x => x % 2 !== 0)).returns(2)\r\n t.is(1, substitute.bar(4))\r\n t.is(2, substitute.bar(5))\r\n})\r\n\r\n\r\ntest.skip('can stub primitive & Arg values', t => {\r\n initialize()\r\n substitute.bar(1).returns(2)\r\n substitute.bar(Arg.any()).returns(3) // throws 'substitute.bar(...).returns is not a function'\r\n t.is(5, substitute.bar(2))\r\n t.is(2, substitute.bar(1))\r\n t.is(3, substitute.bar(2))\r\n})"]} \ No newline at end of file diff --git a/dist/spec/issues/11.test.d.ts b/dist/spec/issues/11.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/11.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/11.test.js b/dist/spec/issues/11.test.js deleted file mode 100644 index ee27853..0000000 --- a/dist/spec/issues/11.test.js +++ /dev/null @@ -1,64 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var _this = this; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -var RealCalculator = /** @class */ (function () { - function RealCalculator() { - } - RealCalculator.prototype.add = function (addands) { - return addands.op1 + addands.op2; - }; - return RealCalculator; -}()); -ava_1.default('issue 11: arg.is is only called once', function (t) { return __awaiter(_this, void 0, void 0, function () { - var mockedCalculator, count; - return __generator(this, function (_a) { - mockedCalculator = index_1.Substitute.for(); - mockedCalculator.add(index_1.Arg.any()).returns(4); - count = 0; - mockedCalculator.add({ op1: 1, op2: 2 }); - mockedCalculator.received(1).add(index_1.Arg.is(function (a) { - count++; - return a.op1 === 1 && a.op2 === 2; - })); - t.is(count, 1); - return [2 /*return*/]; - }); -}); }); -//# sourceMappingURL=11.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/11.test.js.map b/dist/spec/issues/11.test.js.map deleted file mode 100644 index 7c46132..0000000 --- a/dist/spec/issues/11.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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.d.ts b/dist/spec/issues/15.test.d.ts deleted file mode 100644 index f26baed..0000000 --- a/dist/spec/issues/15.test.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface Example { - bar: string; -} diff --git a/dist/spec/issues/15.test.js b/dist/spec/issues/15.test.js deleted file mode 100644 index 5b083a8..0000000 --- a/dist/spec/issues/15.test.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -ava_1.default('issue 15: can call properties twice', function (t) { - var baz = "baz"; - var foo = index_1.Substitute.for(); - foo.bar.returns(baz); - var call1 = foo.bar; - var call2 = foo.bar; - t.is(call1, baz); - t.is(call2, baz); -}); -//# sourceMappingURL=15.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/15.test.js.map b/dist/spec/issues/15.test.js.map deleted file mode 100644 index 2364d05..0000000 --- a/dist/spec/issues/15.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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.d.ts b/dist/spec/issues/18.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/18.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/18.test.js b/dist/spec/issues/18.test.js deleted file mode 100644 index 500023e..0000000 --- a/dist/spec/issues/18.test.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -ava_1.default('issue 18: receive with arg', function (t) { - var mockedCalculator = index_1.Substitute.for(); - mockedCalculator.add(1, index_1.Arg.is(function (input) { return input === 2; })).returns(4); - void mockedCalculator.add(1, 2); - mockedCalculator.received(1).add(1, index_1.Arg.is(function (input) { return input === 2; })); - t.pass(); -}); -//# sourceMappingURL=18.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/18.test.js.map b/dist/spec/issues/18.test.js.map deleted file mode 100644 index cd0164a..0000000 --- a/dist/spec/issues/18.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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.d.ts b/dist/spec/issues/23.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/23.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/23.test.js b/dist/spec/issues/23.test.js deleted file mode 100644 index 05a08b5..0000000 --- a/dist/spec/issues/23.test.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -ava_1.default("issue 23: mimick received should not call method", function (t) { - var mockedCalculator = index_1.Substitute.for(); - var calls = 0; - mockedCalculator.add(index_1.Arg.all()).mimicks(function (a, b) { - t.deepEqual(++calls, 1, 'mimick called twice'); - return a + b; - }); - mockedCalculator.add(1, 1); // ok - mockedCalculator.received(1).add(1, 1); // not ok, calls mimick func -}); -//# sourceMappingURL=23.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/23.test.js.map b/dist/spec/issues/23.test.js.map deleted file mode 100644 index 637b806..0000000 --- a/dist/spec/issues/23.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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.d.ts b/dist/spec/issues/25.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/25.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/25.test.js b/dist/spec/issues/25.test.js deleted file mode 100644 index 6e8b3df..0000000 --- a/dist/spec/issues/25.test.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -ava_1.default('issue 25_2', function (t) { - var calc = index_1.Substitute.for(); - calc.add(index_1.Arg.all()).returns(1337); - calc.add(2, 5); - t.notThrows(function () { return calc.received().add(2, 5); }); -}); -ava_1.default('issue 25_1: call verification does not work when using Arg.all() to set up return values', function (t) { - var calc = index_1.Substitute.for(); - calc.add(index_1.Arg.all()).returns(1337); - calc.add(2, 5); - t.throws(function () { return calc.received().add(3, 4); }); -}); -//# sourceMappingURL=25.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/25.test.js.map b/dist/spec/issues/25.test.js.map deleted file mode 100644 index 3406037..0000000 --- a/dist/spec/issues/25.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/36.test.d.ts b/dist/spec/issues/36.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/36.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/36.test.js b/dist/spec/issues/36.test.js deleted file mode 100644 index 9829953..0000000 --- a/dist/spec/issues/36.test.js +++ /dev/null @@ -1,63 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var _this = this; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -ava_1.default('issue 36 - promises returning object with properties', function (t) { return __awaiter(_this, void 0, void 0, function () { - var emptyFetch, now, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - emptyFetch = index_1.Substitute.for(); - now = new Date(); - emptyFetch.getUpdates(null).returns(Promise.resolve({ - serverCheck: now, - data: { a: [1] } - })); - return [4 /*yield*/, emptyFetch.getUpdates(null)]; - case 1: - result = _a.sent(); - t.true(result.serverCheck instanceof Date, 'given date is instanceof Date'); - t.is(result.serverCheck, now, 'dates are the same'); - t.true(Array.isArray(result.data.a), 'deep array isArray'); - t.deepEqual(result.data.a, [1], 'arrays are deep equal'); - return [2 /*return*/]; - } - }); -}); }); -//# sourceMappingURL=36.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/36.test.js.map b/dist/spec/issues/36.test.js.map deleted file mode 100644 index 99cb5f9..0000000 --- a/dist/spec/issues/36.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"36.test.js","sourceRoot":"","sources":["../../../spec/issues/36.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAoBA;;AApBA,2BAAuB;AAEvB,yCAAkD;AAKlD,aAAI,CAAC,sDAAsD,EAAE,UAAM,CAAC;;;;;gBAC1D,UAAU,GAAG,kBAAU,CAAC,GAAG,EAAU,CAAC;gBACtC,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAQ;oBACvD,WAAW,EAAE,GAAG;oBAChB,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;iBACnB,CAAC,CAAC,CAAC;gBACW,qBAAM,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAA;;gBAA1C,MAAM,GAAG,SAAiC;gBAChD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,YAAY,IAAI,EAAE,+BAA+B,CAAC,CAAC;gBAC5E,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,oBAAoB,CAAC,CAAC;gBACpD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;gBAC3D,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC;;;;KAC5D,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute, Arg } from '../../src/index';\r\n\r\ninterface IData { serverCheck: Date, data: { a: any[] } }\r\ninterface IFetch { getUpdates: (arg: Date | null) => Promise }\r\n\r\ntest('issue 36 - promises returning object with properties', async t => {\r\n const emptyFetch = Substitute.for();\r\n const now = new Date();\r\n emptyFetch.getUpdates(null).returns(Promise.resolve({\r\n serverCheck: now,\r\n data: { a: [1] }\r\n }));\r\n const result = await emptyFetch.getUpdates(null);\r\n t.true(result.serverCheck instanceof Date, 'given date is instanceof Date');\r\n t.is(result.serverCheck, now, 'dates are the same');\r\n t.true(Array.isArray(result.data.a), 'deep array isArray');\r\n t.deepEqual(result.data.a, [1], 'arrays are deep equal');\r\n});\r\n"]} \ No newline at end of file diff --git a/dist/spec/issues/8.test.d.ts b/dist/spec/issues/8.test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/spec/issues/8.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/spec/issues/8.test.js b/dist/spec/issues/8.test.js deleted file mode 100644 index bdbcf3e..0000000 --- a/dist/spec/issues/8.test.js +++ /dev/null @@ -1,79 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var _this = this; -Object.defineProperty(exports, "__esModule", { value: true }); -var index_1 = require("../../src/index"); -var ava_1 = require("ava"); -var ClassA = /** @class */ (function () { - function ClassA() { - } - ClassA.prototype.methodA = function () { - return 'abc'; - }; - return ClassA; -}()); -var ClassB = /** @class */ (function () { - function ClassB(classA) { - this.classA = classA; - } - ClassB.prototype.methodB = function () { - return this.classA.methodA(); - }; - ClassB.prototype.methodB2 = function () { - return 'def'; - }; - return ClassB; -}()); -var ClassC = /** @class */ (function () { - function ClassC(classB) { - this.classB = classB; - } - ClassC.prototype.methodC = function () { - return this.classB.methodB2(); - }; - return ClassC; -}()); -ava_1.default('issue 8: can use substitute in arguments', function (t) { return __awaiter(_this, void 0, void 0, function () { - var classBMock, classC; - return __generator(this, function (_a) { - classBMock = index_1.default.for(); - classC = new ClassC(classBMock); - t.not(classC, null); - return [2 /*return*/]; - }); -}); }); -//# sourceMappingURL=8.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/8.test.js.map b/dist/spec/issues/8.test.js.map deleted file mode 100644 index 8ef1476..0000000 --- a/dist/spec/issues/8.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/spec/issues/9.test.d.ts b/dist/spec/issues/9.test.d.ts deleted file mode 100644 index 3873169..0000000 --- a/dist/spec/issues/9.test.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare class Example { - a: string; - blocking(): Promise; -} diff --git a/dist/spec/issues/9.test.js b/dist/spec/issues/9.test.js deleted file mode 100644 index 2dffd50..0000000 --- a/dist/spec/issues/9.test.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var _this = this; -Object.defineProperty(exports, "__esModule", { value: true }); -var ava_1 = require("ava"); -var index_1 = require("../../src/index"); -var Example = /** @class */ (function () { - function Example() { - this.a = "1337"; - } - Example.prototype.blocking = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, 123]; - }); - }); - }; - return Example; -}()); -exports.Example = Example; -var substitute = index_1.Substitute.for(); -ava_1.default('issue 9: can record method with 0 arguments', function (t) { return __awaiter(_this, void 0, void 0, function () { - function service() { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, substitute.blocking()]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); - } - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - substitute.blocking().returns(Promise.resolve(42)); - return [4 /*yield*/, service()]; - case 1: - _a.sent(); - substitute.received(1).blocking(); - t.pass(); - return [2 /*return*/]; - } - }); -}); }); -//# sourceMappingURL=9.test.js.map \ No newline at end of file diff --git a/dist/spec/issues/9.test.js.map b/dist/spec/issues/9.test.js.map deleted file mode 100644 index 65a40fa..0000000 --- a/dist/spec/issues/9.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"9.test.js","sourceRoot":"","sources":["../../../spec/issues/9.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAuBG;;AAvBH,2BAAuB;AAEvB,yCAA6C;AAG7C;IAAA;QACC,MAAC,GAAG,MAAM,CAAC;IAKZ,CAAC;IAHM,0BAAQ,GAAd;;;gBACC,sBAAO,GAAG,EAAC;;;KACX;IACF,cAAC;AAAD,CAAC,AAND,IAMC;AANY,0BAAO;AAQpB,IAAI,UAAU,GAAG,kBAAU,CAAC,GAAG,EAAW,CAAC;AAE3C,aAAI,CAAC,6CAA6C,EAAE,UAAM,CAAC;IAE1D,SAAe,OAAO;;;;4BACb,qBAAM,UAAU,CAAC,QAAQ,EAAE,EAAA;4BAAlC,sBAAO,SAA2B,EAAC;;;;KACpC;;;;gBAHD,UAAU,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;gBAInD,qBAAM,OAAO,EAAE,EAAA;;gBAAf,SAAe,CAAC;gBAChB,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAC/B,CAAC,CAAC,IAAI,EAAE,CAAC;;;;KACZ,CAAC,CAAC","sourcesContent":["import test from 'ava';\r\n\r\nimport { Substitute } from '../../src/index';\r\nimport { ObjectSubstitute } from '../../src/Transformations';\r\n\r\nexport class Example {\r\n\ta = \"1337\";\r\n\r\n\tasync blocking() {\r\n\t\treturn 123;\r\n\t}\r\n}\r\n\r\nlet substitute = Substitute.for();\r\n\r\ntest('issue 9: can record method with 0 arguments', async t => {\r\n\tsubstitute.blocking().returns(Promise.resolve(42));\r\n\tasync function service() {\r\n\t\t return await substitute.blocking();\r\n\t}\r\n\tawait service();\r\n\tsubstitute.received(1).blocking();\r\n t.pass();\r\n});"]} \ No newline at end of file diff --git a/dist/src/Arguments.d.ts b/dist/src/Arguments.d.ts deleted file mode 100644 index 2878d83..0000000 --- a/dist/src/Arguments.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -export declare class Argument { - private description; - private matchingFunction; - constructor(description: string, matchingFunction: (arg: T) => boolean); - matches(arg: T): boolean; - toString(): string; - inspect(): string; -} -export declare class AllArguments extends Argument { - constructor(); -} -export declare class Arg { - private static _all; - static all(): AllArguments; - static any(): Argument & any; - static any(type: T): Argument & string; - static any(type: T): Argument & number; - static any(type: T): Argument & boolean; - static any(type: T): Argument & any[]; - static any(type: T): Argument & Function; - static any(type: T): Argument & any; - static is(predicate: (input: any) => boolean): Argument & T; - private static toStringify; -} diff --git a/dist/src/Arguments.js b/dist/src/Arguments.js deleted file mode 100644 index 64a77b8..0000000 --- a/dist/src/Arguments.js +++ /dev/null @@ -1,72 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __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; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var Argument = /** @class */ (function () { - function Argument(description, matchingFunction) { - this.description = description; - this.matchingFunction = matchingFunction; - } - Argument.prototype.matches = function (arg) { - return this.matchingFunction(arg); - }; - Argument.prototype.toString = function () { - return this.description; - }; - Argument.prototype.inspect = function () { - return this.description; - }; - return Argument; -}()); -exports.Argument = Argument; -var AllArguments = /** @class */ (function (_super) { - __extends(AllArguments, _super); - function AllArguments() { - return _super.call(this, '{all}', function () { return true; }) || this; - } - return AllArguments; -}(Argument)); -exports.AllArguments = AllArguments; -var Arg = /** @class */ (function () { - function Arg() { - } - Arg.all = function () { - return this._all = (this._all || new AllArguments()); - }; - Arg.any = function (type) { - var description = !type ? '{any arg}' : '{type ' + type + '}'; - return new Argument(description, function (x) { - if (!type) - return true; - if (typeof x === 'undefined') - return true; - if (type === 'array') - return x && Array.isArray(x); - return typeof x === type; - }); - }; - Arg.is = function (predicate) { - return new Argument('{predicate ' + this.toStringify(predicate) + '}', predicate); - }; - Arg.toStringify = function (obj) { - if (typeof obj.inspect === 'function') - return obj.inspect(); - if (typeof obj.toString === 'function') - return obj.toString(); - return obj; - }; - return Arg; -}()); -exports.Arg = Arg; -//# sourceMappingURL=Arguments.js.map \ No newline at end of file diff --git a/dist/src/Arguments.js.map b/dist/src/Arguments.js.map deleted file mode 100644 index bf8cd9a..0000000 --- a/dist/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OAAO,CAAC,CAAC,CAAC,CAAC;YAEjC,OAAO,OAAO,CAAC,KAAK,IAAI,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,MAAE,GAAT,UAAa,SAAkC;QAC3C,OAAO,IAAI,QAAQ,CAAI,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,SAAS,CAAoB,CAAC;IAC5G,CAAC;IAEc,eAAW,GAA1B,UAA2B,GAAQ;QAC/B,IAAG,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU;YAChC,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;QAEzB,IAAG,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU;YACjC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;QAE1B,OAAO,GAAG,CAAC;IACf,CAAC;IACL,UAAC;AAAD,CAAC,AA3CD,IA2CC;AA3CY,kBAAG","sourcesContent":["export class Argument {\r\n\r\n constructor(\r\n private description: string,\r\n private matchingFunction: (arg: T) => boolean\r\n ){}\r\n\r\n matches(arg: T) {\r\n return this.matchingFunction(arg);\r\n }\r\n\r\n toString() {\r\n return this.description;\r\n }\r\n\r\n inspect() {\r\n return this.description;\r\n }\r\n}\r\n\r\nexport class AllArguments extends Argument {\r\n constructor() {\r\n super('{all}', () => true);\r\n }\r\n}\r\n\r\nexport class Arg {\r\n private static _all: AllArguments;\r\n\r\n static all() {\r\n return this._all = (this._all || new AllArguments());\r\n }\r\n\r\n static any(): Argument & any\r\n static any(type: T): Argument & string\r\n static any(type: T): Argument & number\r\n static any(type: T): Argument & boolean\r\n static any(type: T): Argument & any[]\r\n static any(type: T): Argument & Function\r\n static any(type: T): Argument & any\r\n static any(type?: string): Argument & any {\r\n const description = !type ? '{any arg}' : '{type ' + type + '}';\r\n return new Argument(description, x => {\r\n if(!type)\r\n return true;\r\n\r\n if(typeof x === 'undefined')\r\n return true;\r\n\r\n if(type === 'array')\r\n return x && Array.isArray(x);\r\n\r\n return typeof x === type;\r\n });\r\n }\r\n\r\n static is(predicate: (input: any) => boolean): Argument & T {\r\n return new Argument('{predicate ' + this.toStringify(predicate) + '}', predicate) as Argument & T;\r\n }\r\n\r\n private static toStringify(obj: any) {\r\n if(typeof obj.inspect === 'function')\r\n return obj.inspect();\r\n\r\n if(typeof obj.toString === 'function')\r\n return obj.toString();\r\n\r\n return obj;\r\n }\r\n}"]} \ No newline at end of file diff --git a/dist/src/Context.d.ts b/dist/src/Context.d.ts deleted file mode 100644 index e820c49..0000000 --- a/dist/src/Context.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ContextState } from "./states/ContextState"; -import { InitialState } from "./states/InitialState"; -export declare class Context { - private _initialState; - private _proxy; - private _rootProxy; - private _state; - constructor(); - apply(args: any[]): any; - set(property: PropertyKey, value: any): void; - get(property: PropertyKey): any; - readonly proxy: any; - readonly rootProxy: any; - readonly initialState: InitialState; - state: ContextState; -} diff --git a/dist/src/Context.js b/dist/src/Context.js deleted file mode 100644 index 05cff00..0000000 --- a/dist/src/Context.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var InitialState_1 = require("./states/InitialState"); -var Substitute_1 = require("./Substitute"); -var Context = /** @class */ (function () { - function Context() { - var _this_1 = this; - this._initialState = new InitialState_1.InitialState(); - this._state = this._initialState; - this._proxy = new Proxy(function () { }, { - apply: function (_target, _this, args) { - return _this_1.apply(args); - }, - set: function (_target, property, value) { - _this_1.set(property, value); - return true; - }, - get: function (_target, property) { - return _this_1.get(property); - } - }); - this._rootProxy = new Proxy(function () { }, { - apply: function (_target, _this, args) { - return _this_1.initialState.apply(_this_1, args); - }, - set: function (_target, property, value) { - _this_1.initialState.set(_this_1, property, value); - return true; - }, - get: function (_target, property) { - return _this_1.initialState.get(_this_1, property); - } - }); - } - Context.prototype.apply = function (args) { - return this._state.apply(this, args); - }; - Context.prototype.set = function (property, value) { - return this._state.set(this, property, value); - }; - Context.prototype.get = function (property) { - if (property === Substitute_1.HandlerKey) - return this; - return this._state.get(this, property); - }; - Object.defineProperty(Context.prototype, "proxy", { - get: function () { - return this._proxy; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Context.prototype, "rootProxy", { - get: function () { - return this._rootProxy; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Context.prototype, "initialState", { - get: function () { - return this._initialState; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Context.prototype, "state", { - set: function (state) { - if (this._state === state) - return; - this._state = state; - if (state.onSwitchedTo) - state.onSwitchedTo(this); - }, - enumerable: true, - configurable: true - }); - return Context; -}()); -exports.Context = Context; -//# sourceMappingURL=Context.js.map \ No newline at end of file diff --git a/dist/src/Context.js.map b/dist/src/Context.js.map deleted file mode 100644 index 54f79e5..0000000 --- a/dist/src/Context.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/Context.ts"],"names":[],"mappings":";;AACA,sDAAqD;AACrD,2CAA0C;AAE1C;IAQI;QAAA,mBA6BC;QA5BG,IAAI,CAAC,aAAa,GAAG,IAAI,2BAAY,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;QAEjC,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,cAAQ,CAAC,EAAE;YAC/B,KAAK,EAAE,UAAC,OAAO,EAAE,KAAK,EAAE,IAAI;gBACxB,OAAO,OAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YACD,GAAG,EAAE,UAAC,OAAO,EAAE,QAAQ,EAAE,KAAK;gBAC1B,OAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;gBAC1B,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,GAAG,EAAE,UAAC,OAAO,EAAE,QAAQ;gBACnB,OAAO,OAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC9B,CAAC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CAAC,aAAa,CAAC;QAC9B,CAAC;;;OAAA;IAED,sBAAW,0BAAK;aAAhB,UAAiB,KAAmB;YAChC,IAAG,IAAI,CAAC,MAAM,KAAK,KAAK;gBACpB,OAAO;YAEX,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAG,KAAK,CAAC,YAAY;gBACjB,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;;;OAAA;IACL,cAAC;AAAD,CAAC,AA1ED,IA0EC;AA1EY,0BAAO","sourcesContent":["import { ContextState } from \"./states/ContextState\";\r\nimport { InitialState } from \"./states/InitialState\";\r\nimport { HandlerKey } from \"./Substitute\";\r\n\r\nexport class Context {\r\n private _initialState: InitialState;\r\n\r\n private _proxy: any;\r\n private _rootProxy: any;\r\n \r\n private _state: ContextState;\r\n\r\n constructor() {\r\n this._initialState = new InitialState();\r\n this._state = this._initialState;\r\n\r\n this._proxy = new Proxy(() => { }, {\r\n apply: (_target, _this, args) => {\r\n return this.apply(args);\r\n },\r\n set: (_target, property, value) => {\r\n this.set(property, value);\r\n return true;\r\n },\r\n get: (_target, property) => {\r\n return this.get(property);\r\n }\r\n });\r\n\r\n this._rootProxy = new Proxy(() => { }, {\r\n apply: (_target, _this, args) => {\r\n return this.initialState.apply(this, args);\r\n },\r\n set: (_target, property, value) => {\r\n this.initialState.set(this, property, value);\r\n return true;\r\n },\r\n get: (_target, property) => {\r\n return this.initialState.get(this, property);\r\n }\r\n });\r\n }\r\n\r\n apply(args: any[]) {\r\n return this._state.apply(this, args);\r\n }\r\n\r\n set(property: PropertyKey, value: any) {\r\n return this._state.set(this, property, value);\r\n }\r\n\r\n get(property: PropertyKey) {\r\n if(property === HandlerKey)\r\n return this;\r\n\r\n return this._state.get(this, property);\r\n }\r\n\r\n public get proxy() {\r\n return this._proxy;\r\n }\r\n\r\n public get rootProxy() {\r\n return this._rootProxy;\r\n }\r\n\r\n public get initialState() {\r\n return this._initialState;\r\n }\r\n\r\n public set state(state: ContextState) {\r\n if(this._state === state)\r\n return;\r\n\r\n this._state = state;\r\n if(state.onSwitchedTo)\r\n state.onSwitchedTo(this);\r\n }\r\n}"]} \ No newline at end of file diff --git a/dist/src/Substitute.d.ts b/dist/src/Substitute.d.ts deleted file mode 100644 index 3e8bab3..0000000 --- a/dist/src/Substitute.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -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(): SubstituteOf; - static disableFor>>(substitute: T): DisabledSubstituteObject; -} diff --git a/dist/src/Substitute.js b/dist/src/Substitute.js deleted file mode 100644 index 15a220e..0000000 --- a/dist/src/Substitute.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spread = (this && this.__spread) || function () { - for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); - return ar; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Context_1 = require("./Context"); -exports.HandlerKey = Symbol(); -exports.AreProxiesDisabledKey = Symbol(); -var Substitute = /** @class */ (function () { - function Substitute() { - } - Substitute.for = function () { - var objectContext = new Context_1.Context(); - return objectContext.rootProxy; - }; - Substitute.disableFor = function (substitute) { - var thisProxy = substitute; - var thisExposedProxy = thisProxy[exports.HandlerKey]; - var disableProxy = function (f) { - return function () { - thisProxy[exports.AreProxiesDisabledKey] = true; - var returnValue = f.call.apply(f, __spread([thisExposedProxy], arguments)); - thisProxy[exports.AreProxiesDisabledKey] = false; - return returnValue; - }; - }; - return new Proxy(function () { }, { - apply: disableProxy(thisExposedProxy.apply), - set: disableProxy(thisExposedProxy.set), - get: disableProxy(thisExposedProxy.get) - }); - }; - return Substitute; -}()); -exports.Substitute = Substitute; -//# sourceMappingURL=Substitute.js.map \ No newline at end of file diff --git a/dist/src/Substitute.js.map b/dist/src/Substitute.js.map deleted file mode 100644 index 3b8bcf3..0000000 --- a/dist/src/Substitute.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/Transformations.d.ts b/dist/src/Transformations.d.ts deleted file mode 100644 index 182de93..0000000 --- a/dist/src/Transformations.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { AllArguments } from "./Arguments"; -export declare type NoArgumentFunctionSubstitute = (() => (TReturnType & NoArgumentMockObjectMixin)); -export declare type FunctionSubstitute = ((...args: TArguments) => (TReturnType & MockObjectMixin)) & ((allArguments: AllArguments) => (TReturnType & MockObjectMixin)); -export declare type PropertySubstitute = (TReturnType & Partial>); -declare type BaseMockObjectMixin = { - returns: (...args: TReturnType[]) => void; -}; -declare type NoArgumentMockObjectMixin = BaseMockObjectMixin & { - mimicks: (func: () => TReturnType) => void; -}; -declare type MockObjectMixin = BaseMockObjectMixin & { - mimicks: (func: (...args: TArguments) => TReturnType) => void; -}; -export declare type ObjectSubstitute = ObjectSubstituteTransformation & { - received(amount?: number): TerminatingObject; - didNotReceive(amount?: number): TerminatingObject; - mimick(instance: T): void; -}; -declare type TerminatingObject = { - [P in keyof T]: T[P] extends () => infer R ? () => void : T[P] extends (...args: infer F) => infer R ? (...args: F) => void : T[P]; -}; -declare type ObjectSubstituteTransformation = { - [P in keyof T]: T[P] extends () => infer R ? NoArgumentFunctionSubstitute : T[P] extends (...args: infer F) => infer R ? FunctionSubstitute : PropertySubstitute; -}; -declare type Omit = Pick>; -export declare type OmitProxyMethods = Omit; -export declare type DisabledSubstituteObject = T extends ObjectSubstitute, infer K> ? K : never; -export {}; diff --git a/dist/src/Transformations.js b/dist/src/Transformations.js deleted file mode 100644 index 03c70c9..0000000 --- a/dist/src/Transformations.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=Transformations.js.map \ No newline at end of file diff --git a/dist/src/Transformations.js.map b/dist/src/Transformations.js.map deleted file mode 100644 index 05ea9ee..0000000 --- a/dist/src/Transformations.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Transformations.js","sourceRoot":"","sources":["../../src/Transformations.ts"],"names":[],"mappings":"","sourcesContent":["import { AllArguments } from \"./Arguments\";\r\n\r\nexport type NoArgumentFunctionSubstitute = \r\n (() => (TReturnType & NoArgumentMockObjectMixin))\r\n\r\nexport type FunctionSubstitute = \r\n ((...args: TArguments) => (TReturnType & MockObjectMixin)) & \r\n ((allArguments: AllArguments) => (TReturnType & MockObjectMixin))\r\n\r\nexport type PropertySubstitute = (TReturnType & Partial>);\r\n\r\ntype BaseMockObjectMixin = {\r\n returns: (...args: TReturnType[]) => void;\r\n}\r\n\r\ntype NoArgumentMockObjectMixin = BaseMockObjectMixin & {\r\n mimicks: (func: () => TReturnType) => void;\r\n}\r\n\r\ntype MockObjectMixin = BaseMockObjectMixin & {\r\n mimicks: (func: (...args: TArguments) => TReturnType) => void;\r\n}\r\n\r\nexport type ObjectSubstitute = ObjectSubstituteTransformation & {\r\n received(amount?: number): TerminatingObject;\r\n didNotReceive(amount?: number): TerminatingObject;\r\n mimick(instance: T): void;\r\n}\r\n\r\ntype TerminatingObject = {\r\n [P in keyof T]:\r\n T[P] extends () => infer R ? () => void :\r\n T[P] extends (...args: infer F) => infer R ? (...args: F) => void : \r\n T[P];\r\n}\r\n\r\ntype ObjectSubstituteTransformation = {\r\n [P in keyof T]:\r\n T[P] extends () => infer R ? NoArgumentFunctionSubstitute :\r\n T[P] extends (...args: infer F) => infer R ? FunctionSubstitute :\r\n PropertySubstitute;\r\n}\r\n\r\ntype Omit = Pick>;\r\n\r\nexport type OmitProxyMethods = Omit;\r\n\r\nexport type DisabledSubstituteObject = T extends ObjectSubstitute, infer K> ? K : never;"]} \ No newline at end of file diff --git a/dist/src/Utilities.d.ts b/dist/src/Utilities.d.ts deleted file mode 100644 index 841d1f9..0000000 --- a/dist/src/Utilities.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export declare type Call = any[]; -export declare function stringifyArguments(args: any[]): string; -export declare function areArgumentArraysEqual(a: any[], b: any[]): boolean; -export declare function stringifyCalls(calls: Call[]): string; -export declare function areArgumentsEqual(a: any, b: any): boolean; diff --git a/dist/src/Utilities.js b/dist/src/Utilities.js deleted file mode 100644 index d7ed39a..0000000 --- a/dist/src/Utilities.js +++ /dev/null @@ -1,69 +0,0 @@ -"use strict"; -var __values = (this && this.__values) || function (o) { - var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; - if (m) return m.call(o); - return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Arguments_1 = require("./Arguments"); -var util = require("util"); -function stringifyArguments(args) { - args = args.map(function (x) { return util.inspect(x); }); - return args && args.length > 0 ? 'arguments [' + args.join(', ') + ']' : 'no arguments'; -} -exports.stringifyArguments = stringifyArguments; -; -function areArgumentArraysEqual(a, b) { - if (a.find(function (x) { return x instanceof Arguments_1.AllArguments; }) || b.find(function (b) { return b instanceof Arguments_1.AllArguments; })) { - return true; - } - for (var i = 0; i < Math.max(b.length, a.length); i++) { - if (!areArgumentsEqual(b[i], a[i])) { - return false; - } - } - return true; -} -exports.areArgumentArraysEqual = areArgumentArraysEqual; -function stringifyCalls(calls) { - var e_1, _a; - if (calls.length === 0) - return ' (no calls)'; - var output = ''; - try { - for (var calls_1 = __values(calls), calls_1_1 = calls_1.next(); !calls_1_1.done; calls_1_1 = calls_1.next()) { - var call = calls_1_1.value; - output += '\n-> call with ' + (call.length ? stringifyArguments(call) : '(no arguments)'); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (calls_1_1 && !calls_1_1.done && (_a = calls_1.return)) _a.call(calls_1); - } - finally { if (e_1) throw e_1.error; } - } - return output; -} -exports.stringifyCalls = stringifyCalls; -; -function areArgumentsEqual(a, b) { - if (a instanceof Arguments_1.Argument && b instanceof Arguments_1.Argument) { - return false; - } - if (a instanceof Arguments_1.AllArguments || b instanceof Arguments_1.AllArguments) - return true; - if (a instanceof Arguments_1.Argument) - return a.matches(b); - if (b instanceof Arguments_1.Argument) - return b.matches(a); - return a === b; -} -exports.areArgumentsEqual = areArgumentsEqual; -; -//# sourceMappingURL=Utilities.js.map \ No newline at end of file diff --git a/dist/src/Utilities.js.map b/dist/src/Utilities.js.map deleted file mode 100644 index e0f2d97..0000000 --- a/dist/src/Utilities.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../../src/Utilities.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAqD;AACrD,2BAA6B;AAI7B,SAAgB,kBAAkB,CAAC,IAAW;IAC1C,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC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,gBAAgB,CAAC,CAAA;SAC5F;;;;;;;;;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAXD,wCAWC;AAAA,CAAC;AAEF,SAAgB,iBAAiB,CAAC,CAAM,EAAE,CAAM;IAE5C,IAAG,CAAC,YAAY,oBAAQ,IAAI,CAAC,YAAY,oBAAQ,EAAE;QAC/C,OAAO,KAAK,CAAC;KAChB;IAED,IAAG,CAAC,YAAY,wBAAY,IAAI,CAAC,YAAY,wBAAY;QACrD,OAAO,IAAI,CAAC;IAEhB,IAAG,CAAC,YAAY,oBAAQ;QACpB,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAExB,IAAG,CAAC,YAAY,oBAAQ;QACpB,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAhBD,8CAgBC;AAAA,CAAC","sourcesContent":["import { Argument, AllArguments } from \"./Arguments\";\r\nimport util = require('util')\r\n\r\nexport type Call = any[] // list of args\r\n\r\nexport function stringifyArguments(args: any[]) {\r\n args = args.map(x => util.inspect(x));\r\n return args && args.length > 0 ? 'arguments [' + args.join(', ') + ']' : 'no arguments';\r\n};\r\n\r\nexport function areArgumentArraysEqual(a: any[], b: any[]) {\r\n if (a.find(x => x instanceof AllArguments) || b.find(b => b instanceof AllArguments)) {\r\n return true;\r\n }\r\n\r\n for (var i = 0; i < Math.max(b.length, a.length); i++) {\r\n if (!areArgumentsEqual(b[i], a[i])) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n}\r\n\r\nexport function stringifyCalls(calls: Call[]) {\r\n\r\n if(calls.length === 0)\r\n return ' (no calls)';\r\n\r\n let output = '';\r\n for (let call of calls) {\r\n output += '\\n-> call with ' + (call.length ? stringifyArguments(call) : '(no arguments)')\r\n }\r\n\r\n return output;\r\n};\r\n\r\nexport function areArgumentsEqual(a: any, b: any) {\r\n \r\n if(a instanceof Argument && b instanceof Argument) {\r\n return false;\r\n }\r\n\r\n if(a instanceof AllArguments || b instanceof AllArguments)\r\n return true;\r\n\r\n if(a instanceof Argument) \r\n return a.matches(b);\r\n\r\n if(b instanceof Argument)\r\n return b.matches(a);\r\n\r\n return a === b;\r\n};"]} \ No newline at end of file diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts deleted file mode 100644 index 3a45d48..0000000 --- a/dist/src/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Substitute, SubstituteOf } from './Substitute'; -export { Arg } from './Arguments'; -export { Substitute, SubstituteOf }; -export default Substitute; diff --git a/dist/src/index.js b/dist/src/index.js deleted file mode 100644 index a84853b..0000000 --- a/dist/src/index.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Substitute_1 = require("./Substitute"); -exports.Substitute = Substitute_1.Substitute; -var Arguments_1 = require("./Arguments"); -exports.Arg = Arguments_1.Arg; -exports.default = Substitute_1.Substitute; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/src/index.js.map b/dist/src/index.js.map deleted file mode 100644 index f006580..0000000 --- a/dist/src/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/ContextState.d.ts b/dist/src/states/ContextState.d.ts deleted file mode 100644 index ba64338..0000000 --- a/dist/src/states/ContextState.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Context } from "../Context"; -import { FunctionState } from "./FunctionState"; -export declare type PropertyKey = string | number | symbol; -export interface ContextState { - onSwitchedTo?(context: Context): void; - apply(context: Context, args: any[], matchingFunctionStates?: FunctionState[]): any; - set(context: Context, property: PropertyKey, value: any): void; - get(context: Context, property: PropertyKey): any; -} diff --git a/dist/src/states/ContextState.js b/dist/src/states/ContextState.js deleted file mode 100644 index ed3419d..0000000 --- a/dist/src/states/ContextState.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=ContextState.js.map \ No newline at end of file diff --git a/dist/src/states/ContextState.js.map b/dist/src/states/ContextState.js.map deleted file mode 100644 index 583c9f6..0000000 --- a/dist/src/states/ContextState.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ContextState.js","sourceRoot":"","sources":["../../../src/states/ContextState.ts"],"names":[],"mappings":"","sourcesContent":["import { Context } from \"../Context\";\r\nimport { FunctionState } from \"./FunctionState\";\r\n\r\nexport type PropertyKey = string|number|symbol;\r\n\r\nexport interface ContextState {\r\n onSwitchedTo?(context: Context): void;\r\n apply(context: Context, args: any[], matchingFunctionStates?: FunctionState[]): any;\r\n set(context: Context, property: PropertyKey, value: any): void;\r\n get(context: Context, property: PropertyKey): any;\r\n}"]} \ No newline at end of file diff --git a/dist/src/states/FunctionState.d.ts b/dist/src/states/FunctionState.d.ts deleted file mode 100644 index 19fffd7..0000000 --- a/dist/src/states/FunctionState.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ContextState, PropertyKey } from "./ContextState"; -import { Context } from "src/Context"; -import { Call } from "../Utilities"; -import { GetPropertyState } from "./GetPropertyState"; -export declare class FunctionState implements ContextState { - private _getPropertyState; - private returns; - private mimicks; - private _calls; - private _lastArgs?; - readonly calls: Call[]; - readonly callCount: number; - readonly property: string | number | symbol; - constructor(_getPropertyState: GetPropertyState); - private getCallCount; - apply(context: Context, args: any[]): any; - set(context: Context, property: PropertyKey, value: any): void; - get(context: Context, property: PropertyKey): any; -} diff --git a/dist/src/states/FunctionState.js b/dist/src/states/FunctionState.js deleted file mode 100644 index 23c69ee..0000000 --- a/dist/src/states/FunctionState.js +++ /dev/null @@ -1,108 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Utilities_1 = require("../Utilities"); -var Nothing = Symbol(); -var FunctionState = /** @class */ (function () { - function FunctionState(_getPropertyState) { - this._getPropertyState = _getPropertyState; - this.returns = []; - this.mimicks = null; - this._calls = []; - } - Object.defineProperty(FunctionState.prototype, "calls", { - get: function () { - return this._calls; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(FunctionState.prototype, "callCount", { - get: function () { - return this._calls.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(FunctionState.prototype, "property", { - get: function () { - return this._getPropertyState.property; - }, - enumerable: true, - configurable: true - }); - FunctionState.prototype.getCallCount = function (args) { - return this._calls.reduce(function (count, cargs) { return Utilities_1.areArgumentArraysEqual(cargs, args) ? count + 1 : count; }, 0); - }; - FunctionState.prototype.apply = function (context, args) { - var hasExpectations = context.initialState.hasExpectations; - this._lastArgs = args; - context.initialState.assertCallCountMatchesExpectations(this._calls, this.getCallCount(args), 'method', this.property, args); - if (!hasExpectations) { - this._calls.push(args); - } - if (!hasExpectations) { - if (this.mimicks) - return this.mimicks.apply(this.mimicks, args); - if (!this.returns.length) - return context.proxy; - var returns = this.returns.find(function (r) { return Utilities_1.areArgumentArraysEqual(r.args, args); }); - if (returns) { - var returnValues = returns.returnValues; - if (returnValues.length === 1) { - return returnValues[0]; - } - if (returnValues.length > returns.returnIndex) { - return returnValues[returns.returnIndex++]; - } - return void 0; // probably a test setup error, imho throwin is more helpful -- domasx2 - //throw Error(`${String(this._getPropertyState.property)} with ${stringifyArguments(returns.args)} called ${returns.returnIndex + 1} times, but only ${returnValues.length} return values were set up`) - } - } - return context.proxy; - }; - FunctionState.prototype.set = function (context, property, value) { - }; - FunctionState.prototype.get = function (context, property) { - var _this = this; - if (property === 'then') - return void 0; - if (property === 'mimicks') { - return function (input) { - _this.mimicks = input; - _this._calls.pop(); - context.state = context.initialState; - }; - } - if (property === 'returns') { - return function () { - var returns = []; - for (var _i = 0; _i < arguments.length; _i++) { - returns[_i] = arguments[_i]; - } - if (!_this._lastArgs) { - throw new Error('Eh, there\'s a bug, no args recorded for this return :/'); - } - _this.returns.push({ - returnValues: returns, - returnIndex: 0, - args: _this._lastArgs - }); - _this._calls.pop(); - if (_this.callCount === 0) { - // var indexOfSelf = this - // ._getPropertyState - // .recordedFunctionStates - // .indexOf(this); - // this._getPropertyState - // .recordedFunctionStates - // .splice(indexOfSelf, 1); - } - context.state = context.initialState; - }; - } - return context.proxy; - }; - return FunctionState; -}()); -exports.FunctionState = FunctionState; -//# sourceMappingURL=FunctionState.js.map \ No newline at end of file diff --git a/dist/src/states/FunctionState.js.map b/dist/src/states/FunctionState.js.map deleted file mode 100644 index 3c159c1..0000000 --- a/dist/src/states/FunctionState.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"FunctionState.js","sourceRoot":"","sources":["../../../src/states/FunctionState.ts"],"names":[],"mappings":";;AAEA,0CAAmH;AAInH,IAAM,OAAO,GAAG,MAAM,EAAE,CAAA;AAQxB;IAmBI,uBAAoB,iBAAmC;QAAnC,sBAAiB,GAAjB,iBAAiB,CAAkB;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAhBD,sBAAW,gCAAK;aAAhB;YACI,OAAO,IAAI,CAAC,MAAM,CAAA;QACtB,CAAC;;;OAAA;IAED,sBAAW,oCAAS;aAApB;YACI,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,CAAC;;;OAAA;IAED,sBAAW,mCAAQ;aAAnB;YACI,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC3C,CAAC;;;OAAA;IAQO,oCAAY,GAApB,UAAqB,IAAU;QAC3B,OAA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A+B;iBAClC;gBAED,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC;YACzC,CAAC,CAAC;SACL;QAED,OAAO,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IACL,oBAAC;AAAD,CAAC,AA/GD,IA+GC;AA/GY,sCAAa","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\r\nimport { Context } from \"src/Context\";\r\nimport { stringifyArguments, stringifyCalls, areArgumentsEqual, areArgumentArraysEqual, Call } from \"../Utilities\";\r\nimport { GetPropertyState } from \"./GetPropertyState\";\r\nimport { Argument, Arg } from \"../Arguments\";\r\n\r\nconst Nothing = Symbol()\r\n\r\ninterface ReturnMock {\r\n args: Call\r\n returnValues: any[] | Symbol // why symbol, what\r\n returnIndex: 0\r\n}\r\n\r\nexport class FunctionState implements ContextState {\r\n private returns: ReturnMock[];\r\n private mimicks: Function|null;\r\n\r\n private _calls: Call[]; // list of lists of arguments this was called with\r\n private _lastArgs?: Call // bit of a hack\r\n\r\n public get calls(): Call[] {\r\n return this._calls\r\n }\r\n\r\n public get callCount() {\r\n return this._calls.length;\r\n }\r\n\r\n public get property() {\r\n return this._getPropertyState.property;\r\n }\r\n\r\n constructor(private _getPropertyState: GetPropertyState) {\r\n this.returns = [];\r\n this.mimicks = null;\r\n this._calls = [];\r\n }\r\n\r\n private getCallCount(args: Call): number {\r\n return this._calls.reduce((count, cargs) => areArgumentArraysEqual(cargs, args) ? count + 1 : count, 0)\r\n }\r\n\r\n apply(context: Context, args: any[]) {\r\n const hasExpectations = context.initialState.hasExpectations;\r\n this._lastArgs = args\r\n\r\n context.initialState.assertCallCountMatchesExpectations(\r\n this._calls,\r\n this.getCallCount(args),\r\n 'method',\r\n this.property,\r\n args);\r\n\r\n if(!hasExpectations) {\r\n this._calls.push(args)\r\n }\r\n\r\n if (!hasExpectations) {\r\n if(this.mimicks)\r\n return this.mimicks.apply(this.mimicks, args);\r\n\r\n if(!this.returns.length)\r\n return context.proxy;\r\n const returns = this.returns.find(r => areArgumentArraysEqual(r.args, args))\r\n\r\n if (returns) {\r\n const returnValues = returns.returnValues as any[]\r\n if (returnValues.length === 1) {\r\n return returnValues[0]\r\n }\r\n if (returnValues.length > returns.returnIndex) {\r\n return returnValues[returns.returnIndex++]\r\n }\r\n return void 0 // probably a test setup error, imho throwin is more helpful -- domasx2\r\n //throw Error(`${String(this._getPropertyState.property)} with ${stringifyArguments(returns.args)} called ${returns.returnIndex + 1} times, but only ${returnValues.length} return values were set up`)\r\n }\r\n }\r\n return context.proxy\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 if (property === 'then')\r\n return void 0;\r\n\r\n if(property === 'mimicks') {\r\n return (input: Function) => {\r\n this.mimicks = input;\r\n this._calls.pop()\r\n\r\n context.state = context.initialState;\r\n }\r\n }\r\n\r\n if(property === 'returns') {\r\n return (...returns: any[]) => {\r\n if (!this._lastArgs) {\r\n throw new Error('Eh, there\\'s a bug, no args recorded for this return :/')\r\n }\r\n this.returns.push({\r\n returnValues: returns,\r\n returnIndex: 0,\r\n args: this._lastArgs\r\n })\r\n this._calls.pop()\r\n\r\n if(this.callCount === 0) {\r\n // var indexOfSelf = this\r\n // ._getPropertyState\r\n // .recordedFunctionStates\r\n // .indexOf(this);\r\n // this._getPropertyState\r\n // .recordedFunctionStates\r\n // .splice(indexOfSelf, 1);\r\n }\r\n\r\n context.state = context.initialState;\r\n };\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/GetPropertyState.d.ts b/dist/src/states/GetPropertyState.d.ts deleted file mode 100644 index 07589d6..0000000 --- a/dist/src/states/GetPropertyState.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ContextState, PropertyKey } from "./ContextState"; -import { Context } from "src/Context"; -import { FunctionState } from "./FunctionState"; -export declare class GetPropertyState implements ContextState { - private _property; - private returns; - private mimicks; - private _callCount; - private _functionState?; - private readonly isFunction; - readonly property: string | number | symbol; - readonly callCount: number; - readonly functionState: FunctionState | undefined; - constructor(_property: PropertyKey); - apply(context: Context, args: any[]): any; - set(context: Context, property: PropertyKey, value: any): void; - get(context: Context, property: PropertyKey): any; -} diff --git a/dist/src/states/GetPropertyState.js b/dist/src/states/GetPropertyState.js deleted file mode 100644 index 2916879..0000000 --- a/dist/src/states/GetPropertyState.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var FunctionState_1 = require("./FunctionState"); -var Nothing = Symbol(); -var GetPropertyState = /** @class */ (function () { - function GetPropertyState(_property) { - this._property = _property; - this.returns = Nothing; - this.mimicks = null; - this._callCount = 0; - } - Object.defineProperty(GetPropertyState.prototype, "isFunction", { - get: function () { - return !!this._functionState; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GetPropertyState.prototype, "property", { - get: function () { - return this._property; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GetPropertyState.prototype, "callCount", { - get: function () { - return this._callCount; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GetPropertyState.prototype, "functionState", { - get: function () { - return this._functionState; - }, - enumerable: true, - configurable: true - }); - GetPropertyState.prototype.apply = function (context, args) { - this._callCount = 0; - if (this.functionState) { - context.state = this.functionState; - return this.functionState.apply(context, args); - } - var functionState = new FunctionState_1.FunctionState(this); - context.state = functionState; - this._functionState = functionState; - return context.apply(args); - }; - GetPropertyState.prototype.set = function (context, property, value) { - }; - GetPropertyState.prototype.get = function (context, property) { - var _this = this; - var hasExpectations = context.initialState.hasExpectations; - if (property === 'then') - return void 0; - if (this.isFunction) - return context.proxy; - if (property === 'mimicks') { - return function (input) { - _this.mimicks = input; - _this._callCount--; - context.state = context.initialState; - }; - } - if (property === 'returns') { - if (this.returns !== Nothing) - throw new Error('The return value for the property ' + this._property.toString() + ' has already been set to ' + this.returns); - return function () { - var returns = []; - for (var _i = 0; _i < arguments.length; _i++) { - returns[_i] = arguments[_i]; - } - _this.returns = returns; - _this._callCount--; - context.state = context.initialState; - }; - } - if (!hasExpectations) { - this._callCount++; - if (this.mimicks) - return this.mimicks.apply(this.mimicks); - if (this.returns !== Nothing) { - var returnsArray = this.returns; - if (returnsArray.length === 1) - return returnsArray[0]; - return returnsArray[this._callCount - 1]; - } - } - context.initialState.assertCallCountMatchesExpectations([[]], // I'm not sure what this was supposed to mean - this.callCount, 'property', this.property, []); - return context.proxy; - }; - return GetPropertyState; -}()); -exports.GetPropertyState = GetPropertyState; -//# sourceMappingURL=GetPropertyState.js.map \ No newline at end of file diff --git a/dist/src/states/GetPropertyState.js.map b/dist/src/states/GetPropertyState.js.map deleted file mode 100644 index b35807f..0000000 --- a/dist/src/states/GetPropertyState.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"GetPropertyState.js","sourceRoot":"","sources":["../../../src/states/GetPropertyState.ts"],"names":[],"mappings":";;AAEA,iDAAgD;AAEhD,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,U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IAAiB;oBAAjB,4BAAiB;;gBACrB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;gBACvB,KAAI,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\";\r\nimport { Context } from \"src/Context\";\r\nimport { FunctionState } from \"./FunctionState\";\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/InitialState.d.ts b/dist/src/states/InitialState.d.ts deleted file mode 100644 index f97e747..0000000 --- a/dist/src/states/InitialState.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ContextState, PropertyKey } from "./ContextState"; -import { Context } from "src/Context"; -import { GetPropertyState } from "./GetPropertyState"; -import { SetPropertyState } from "./SetPropertyState"; -import { Call } from "../Utilities"; -export declare class InitialState implements ContextState { - private recordedGetPropertyStates; - private recordedSetPropertyStates; - private _expectedCount; - private _areProxiesDisabled; - readonly expectedCount: number; - readonly hasExpectations: boolean; - readonly setPropertyStates: SetPropertyState[]; - readonly getPropertyStates: GetPropertyState[]; - constructor(); - assertCallCountMatchesExpectations(calls: Call[], callCount: number, type: string, property: PropertyKey, args: any[]): void; - private doesCallCountMatchExpectations; - apply(context: Context, args: any[]): void; - set(context: Context, property: PropertyKey, value: any): void; - get(context: Context, property: PropertyKey): any; - private clearExpectations; - onSwitchedTo(): void; -} diff --git a/dist/src/states/InitialState.js b/dist/src/states/InitialState.js deleted file mode 100644 index e2253d5..0000000 --- a/dist/src/states/InitialState.js +++ /dev/null @@ -1,144 +0,0 @@ -"use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spread = (this && this.__spread) || function () { - for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); - return ar; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var GetPropertyState_1 = require("./GetPropertyState"); -var SetPropertyState_1 = require("./SetPropertyState"); -var Utilities_1 = require("../Utilities"); -var Substitute_1 = require("../Substitute"); -var InitialState = /** @class */ (function () { - function InitialState() { - this.recordedGetPropertyStates = new Map(); - this.recordedSetPropertyStates = []; - this._areProxiesDisabled = false; - this._expectedCount = void 0; - } - Object.defineProperty(InitialState.prototype, "expectedCount", { - get: function () { - return this._expectedCount; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(InitialState.prototype, "hasExpectations", { - get: function () { - return this._expectedCount !== void 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(InitialState.prototype, "setPropertyStates", { - get: function () { - return __spread(this.recordedSetPropertyStates); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(InitialState.prototype, "getPropertyStates", { - get: function () { - return __spread(this.recordedGetPropertyStates.values()); - }, - enumerable: true, - configurable: true - }); - InitialState.prototype.assertCallCountMatchesExpectations = function (calls, callCount, type, property, args) { - var expectedCount = this._expectedCount; - this.clearExpectations(); - if (this.doesCallCountMatchExpectations(expectedCount, callCount)) - return; - throw new Error('Expected ' + (expectedCount === null ? '1 or more' : expectedCount) + ' call' + (expectedCount === 1 ? '' : 's') + ' to the ' + type + ' ' + property.toString() + ' with ' + Utilities_1.stringifyArguments(args) + ', but received ' + (callCount === 0 ? 'none' : callCount) + ' of such call' + (callCount === 1 ? '' : 's') + '.\nAll calls received to ' + type + ' ' + property.toString() + ':' + Utilities_1.stringifyCalls(calls)); - }; - InitialState.prototype.doesCallCountMatchExpectations = function (expectedCount, actualCount) { - if (expectedCount === void 0) - return true; - if (expectedCount === null && actualCount > 0) - return true; - return expectedCount === actualCount; - }; - InitialState.prototype.apply = function (context, args) { - }; - InitialState.prototype.set = function (context, property, value) { - if (property === Substitute_1.AreProxiesDisabledKey) { - this._areProxiesDisabled = value; - return; - } - var existingSetState = this.recordedSetPropertyStates.find(function (x) { return x.arguments[0] === value; }); - ; - if (existingSetState) { - return existingSetState.set(context, property, value); - } - var setPropertyState = new SetPropertyState_1.SetPropertyState(property, value); - context.state = setPropertyState; - this.recordedSetPropertyStates.push(setPropertyState); - setPropertyState.set(context, property, value); - }; - InitialState.prototype.get = function (context, property) { - var _this = this; - if (typeof property === 'symbol') { - if (property === Substitute_1.AreProxiesDisabledKey) - return this._areProxiesDisabled; - if (property === Symbol.toPrimitive) - return function () { return '{SubstituteJS fake}'; }; - if (property === Symbol.iterator) - return void 0; - if (property === Symbol.toStringTag) - return 'Substitute'; - if (property.toString() === 'Symbol(util.inspect.custom)') - return void 0; - } - if (property === 'valueOf') - return '{SubstituteJS fake}'; - if (property === '$$typeof') - return '{SubstituteJS fake}'; - if (property === 'length') - return '{SubstituteJS fake}'; - if (property === 'toString') - return '{SubstituteJS fake}'; - if (property === 'inspect') - return function () { return '{SubstituteJS fake}'; }; - if (property === 'constructor') - return function () { return context.rootProxy; }; - if (property === 'received') { - return function (count) { - _this._expectedCount = count === void 0 ? null : count; - return context.proxy; - }; - } - var existingGetState = this.recordedGetPropertyStates.get(property); - if (existingGetState) { - context.state = existingGetState; - return context.get(property); - } - var getState = new GetPropertyState_1.GetPropertyState(property); - context.state = getState; - this.recordedGetPropertyStates.set(property, getState); - return context.get(property); - }; - InitialState.prototype.clearExpectations = function () { - this._expectedCount = void 0; - }; - InitialState.prototype.onSwitchedTo = function () { - this.clearExpectations(); - }; - return InitialState; -}()); -exports.InitialState = InitialState; -//# sourceMappingURL=InitialState.js.map \ No newline at end of file diff --git a/dist/src/states/InitialState.js.map b/dist/src/states/InitialState.js.map deleted file mode 100644 index 9d17c4f..0000000 --- a/dist/src/states/InitialState.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"InitialState.js","sourceRoot":"","sources":["../../../src/states/InitialState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,uDAAsD;AACtD,uDAAsD;AACtD,0CAAwE;AACxE,4CAAsD;AAEtD;IAuBI;QACI,IAAI,CAAC,yBAAyB,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3C,IAAI,CAAC,yBAAyB,GAAG,EAAE,CAAC;QAEpC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC;IAtBD,sBAAW,uCAAa;aAAxB;YACI,OAAO,IAAI,CAAC,cAAc,CAAC;QAC/B,CAAC;;;OAAA;IAED,sBAAW,yCAAe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QAEzB,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEvD,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAEO,wCAAiB,GAAzB;QACI,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,mCAAY,GAAZ;QACI,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IACL,mBAAC;AAAD,CAAC,AAxID,IAwIC;AAxIY,oCAAY","sourcesContent":["import { ContextState, PropertyKey } from \"./ContextState\";\r\nimport { Context } from \"src/Context\";\r\nimport { GetPropertyState } from \"./GetPropertyState\";\r\nimport { SetPropertyState } from \"./SetPropertyState\";\r\nimport { stringifyArguments, stringifyCalls, Call } from \"../Utilities\";\r\nimport { AreProxiesDisabledKey } from \"../Substitute\";\r\n\r\nexport class InitialState implements ContextState {\r\n private recordedGetPropertyStates: Map;\r\n private recordedSetPropertyStates: SetPropertyState[];\r\n \r\n private _expectedCount: number|undefined|null;\r\n private _areProxiesDisabled: boolean;\r\n\r\n public get expectedCount() {\r\n return this._expectedCount;\r\n }\r\n\r\n public get hasExpectations() {\r\n return this._expectedCount !== void 0;\r\n }\r\n\r\n public get setPropertyStates() {\r\n return [...this.recordedSetPropertyStates];\r\n }\r\n\r\n public get getPropertyStates() {\r\n return [...this.recordedGetPropertyStates.values()];\r\n }\r\n\r\n constructor() {\r\n this.recordedGetPropertyStates = new Map();\r\n this.recordedSetPropertyStates = [];\r\n\r\n this._areProxiesDisabled = false;\r\n this._expectedCount = void 0;\r\n }\r\n\r\n assertCallCountMatchesExpectations(calls: Call[], callCount: number, type: string, property: PropertyKey, args: any[]) {\r\n const expectedCount = this._expectedCount;\r\n\r\n this.clearExpectations();\r\n if(this.doesCallCountMatchExpectations(expectedCount, callCount))\r\n return;\r\n \r\n throw new Error('Expected ' + (expectedCount === null ? '1 or more' : expectedCount) + ' call' + (expectedCount === 1 ? '' : 's') + ' to the ' + type + ' ' + property.toString() + ' with ' + stringifyArguments(args) + ', but received ' + (callCount === 0 ? 'none' : callCount) + ' of such call' + (callCount === 1 ? '' : 's') + '.\\nAll calls received to ' + type + ' ' + property.toString() + ':' + stringifyCalls(calls));\r\n }\r\n\r\n private doesCallCountMatchExpectations(expectedCount: number|undefined|null, actualCount: number) {\r\n if (expectedCount === void 0)\r\n return true;\r\n\r\n if (expectedCount === null && actualCount > 0)\r\n return true;\r\n\r\n return expectedCount === actualCount;\r\n }\r\n\r\n apply(context: Context, args: any[]) {\r\n }\r\n\r\n set(context: Context, property: PropertyKey, value: any) {\r\n if(property === AreProxiesDisabledKey) {\r\n this._areProxiesDisabled = value;\r\n return;\r\n }\r\n\r\n const existingSetState = this.recordedSetPropertyStates.find(x => x.arguments[0] === value);;\r\n if (existingSetState) {\r\n return existingSetState.set(context, property, value);\r\n }\r\n\r\n const setPropertyState = new SetPropertyState(property, value);\r\n context.state = setPropertyState;\r\n\r\n this.recordedSetPropertyStates.push(setPropertyState);\r\n\r\n setPropertyState.set(context, property, value);\r\n }\r\n\r\n get(context: Context, property: PropertyKey) {\r\n if (typeof property === 'symbol') {\r\n if(property === AreProxiesDisabledKey)\r\n return this._areProxiesDisabled;\r\n\r\n if (property === Symbol.toPrimitive)\r\n return () => '{SubstituteJS fake}';\r\n\r\n if (property === Symbol.iterator)\r\n return void 0;\r\n\r\n if (property === Symbol.toStringTag)\r\n return 'Substitute';\r\n if(property.toString() === 'Symbol(util.inspect.custom)')\r\n return void 0;\r\n }\r\n\r\n if (property === 'valueOf')\r\n return '{SubstituteJS fake}';\r\n\r\n if (property === '$$typeof')\r\n return '{SubstituteJS fake}';\r\n\r\n if (property === 'length')\r\n return '{SubstituteJS fake}';\r\n\r\n if (property === 'toString')\r\n return '{SubstituteJS fake}';\r\n\r\n if (property === 'inspect')\r\n return () => '{SubstituteJS fake}';\r\n\r\n if (property === 'constructor')\r\n return () => context.rootProxy;\r\n\r\n if (property === 'received') {\r\n return (count?: number) => {\r\n this._expectedCount = count === void 0 ? null : count;\r\n return context.proxy;\r\n };\r\n }\r\n\r\n const existingGetState = this.recordedGetPropertyStates.get(property);\r\n if (existingGetState) {\r\n context.state = existingGetState;\r\n return context.get(property);\r\n }\r\n\r\n const getState = new GetPropertyState(property);\r\n context.state = getState;\r\n\r\n this.recordedGetPropertyStates.set(property, getState);\r\n\r\n return context.get(property);\r\n }\r\n\r\n private clearExpectations() {\r\n this._expectedCount = void 0;\r\n }\r\n\r\n onSwitchedTo() {\r\n this.clearExpectations();\r\n }\r\n}"]} \ No newline at end of file diff --git a/dist/src/states/SetPropertyState.d.ts b/dist/src/states/SetPropertyState.d.ts deleted file mode 100644 index c006343..0000000 --- a/dist/src/states/SetPropertyState.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContextState, PropertyKey } from "./ContextState"; -import { Context } from "src/Context"; -export declare class SetPropertyState implements ContextState { - private _property; - private _callCount; - private _arguments; - readonly arguments: any[]; - readonly property: string | number | symbol; - readonly callCount: number; - constructor(_property: PropertyKey, ...args: any[]); - apply(context: Context): undefined; - set(context: Context, property: PropertyKey, value: any): void; - get(context: Context, property: PropertyKey): undefined; -} diff --git a/dist/src/states/SetPropertyState.js b/dist/src/states/SetPropertyState.js deleted file mode 100644 index 21a8f0f..0000000 --- a/dist/src/states/SetPropertyState.js +++ /dev/null @@ -1,61 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Utilities_1 = require("../Utilities"); -var Nothing = Symbol(); -var SetPropertyState = /** @class */ (function () { - function SetPropertyState(_property) { - var args = []; - for (var _i = 1; _i < arguments.length; _i++) { - args[_i - 1] = arguments[_i]; - } - this._property = _property; - this._arguments = args; - this._callCount = 0; - } - Object.defineProperty(SetPropertyState.prototype, "arguments", { - get: function () { - return this._arguments; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SetPropertyState.prototype, "property", { - get: function () { - return this._property; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SetPropertyState.prototype, "callCount", { - get: function () { - return this._callCount; - }, - enumerable: true, - configurable: true - }); - SetPropertyState.prototype.apply = function (context) { - return void 0; - }; - SetPropertyState.prototype.set = function (context, property, value) { - var callCount = this._callCount; - var hasExpectations = context.initialState.hasExpectations; - if (hasExpectations) { - callCount = context.initialState - .setPropertyStates - .filter(function (x) { return Utilities_1.areArgumentsEqual(x.arguments[0], value); }) - .map(function (x) { return x._callCount; }) - .reduce(function (a, b) { return a + b; }, 0); - } - context.initialState.assertCallCountMatchesExpectations([[]], // not sure what this was supposed to do - callCount, 'property', this.property, this.arguments); - if (!hasExpectations) { - this._callCount++; - } - }; - SetPropertyState.prototype.get = function (context, property) { - return void 0; - }; - return SetPropertyState; -}()); -exports.SetPropertyState = SetPropertyState; -//# sourceMappingURL=SetPropertyState.js.map \ No newline at end of file diff --git a/dist/src/states/SetPropertyState.js.map b/dist/src/states/SetPropertyState.js.map deleted file mode 100644 index 0469658..0000000 --- a/dist/src/states/SetPropertyState.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"SetPropertyState.js","sourceRoot":"","sources":["../../../src/states/SetPropertyState.ts"],"names":[],"mappings":";;AAEA,0CAAiD;AAEjD,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 { 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.json b/package.json index b9a1300..c1ea67d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,11 @@ "description": "", "main": "dist/src/index.js", "typings": "./dist/src/index.d.ts", + "files": [ + "dist/src/**/*" + ], "scripts": { + "prepack": "npm i && tsc", "test": "tsc && ava", "build": "tsc" },