ts-mockito
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -12,3 +12,3 @@ "use strict"; | ||
function AnyNumberMatcher() { | ||
_super.call(this); | ||
return _super.call(this) || this; | ||
} | ||
@@ -15,0 +15,0 @@ AnyNumberMatcher.prototype.match = function (value) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
function AnyStringMatcher() { | ||
_super.call(this); | ||
return _super.call(this) || this; | ||
} | ||
@@ -15,0 +15,0 @@ AnyStringMatcher.prototype.match = function (value) { |
@@ -11,3 +11,3 @@ "use strict"; | ||
function AnythingMatcher() { | ||
_super.call(this); | ||
return _super.call(this) || this; | ||
} | ||
@@ -14,0 +14,0 @@ AnythingMatcher.prototype.match = function (value) { |
@@ -11,8 +11,9 @@ "use strict"; | ||
function BetweenMatcher(min, max) { | ||
_super.call(this); | ||
this.min = min; | ||
this.max = max; | ||
var _this = _super.call(this) || this; | ||
_this.min = min; | ||
_this.max = max; | ||
if (min > max) { | ||
throw new Error("between matcher error: min value can\'t be greater than max"); | ||
} | ||
return _this; | ||
} | ||
@@ -19,0 +20,0 @@ BetweenMatcher.prototype.match = function (value) { |
@@ -12,4 +12,5 @@ "use strict"; | ||
function DeepEqualMatcher(expectedValue) { | ||
_super.call(this); | ||
this.expectedValue = expectedValue; | ||
var _this = _super.call(this) || this; | ||
_this.expectedValue = expectedValue; | ||
return _this; | ||
} | ||
@@ -16,0 +17,0 @@ DeepEqualMatcher.prototype.match = function (value) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
function NotNullMatcher() { | ||
_super.apply(this, arguments); | ||
return _super.apply(this, arguments) || this; | ||
} | ||
@@ -15,0 +15,0 @@ NotNullMatcher.prototype.match = function (value) { |
@@ -11,4 +11,5 @@ "use strict"; | ||
function StrictEqualMatcher(expectedValue) { | ||
_super.call(this); | ||
this.expectedValue = expectedValue; | ||
var _this = _super.call(this) || this; | ||
_this.expectedValue = expectedValue; | ||
return _this; | ||
} | ||
@@ -15,0 +16,0 @@ StrictEqualMatcher.prototype.match = function (value) { |
@@ -29,6 +29,6 @@ "use strict"; | ||
}; | ||
MethodAction.globalCallIndex = 0; | ||
return MethodAction; | ||
}()); | ||
MethodAction.globalCallIndex = 0; | ||
exports.MethodAction = MethodAction; | ||
//# sourceMappingURL=MethodAction.js.map |
"use strict"; | ||
var ReturnValueMethodStub_1 = require('./stub/ReturnValueMethodStub'); | ||
var ThrowErrorMethodStub_1 = require('./stub/ThrowErrorMethodStub'); | ||
var CallFunctionMethodStub_1 = require('./stub/CallFunctionMethodStub'); | ||
var CaptorMethodStub_1 = require('./stub/CaptorMethodStub'); | ||
var ReturnValueMethodStub_1 = require("./stub/ReturnValueMethodStub"); | ||
var ThrowErrorMethodStub_1 = require("./stub/ThrowErrorMethodStub"); | ||
var CallFunctionMethodStub_1 = require("./stub/CallFunctionMethodStub"); | ||
var CaptorMethodStub_1 = require("./stub/CaptorMethodStub"); | ||
var MethodStubSetter = (function () { | ||
@@ -22,3 +22,3 @@ function MethodStubSetter(methodToStub) { | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
args[_i] = arguments[_i]; | ||
} | ||
@@ -25,0 +25,0 @@ this.methodToStub.methodStubCollection.add(new CaptorMethodStub_1.CaptorMethodStub(this.methodToStub.matchers, args)); |
@@ -24,3 +24,3 @@ "use strict"; | ||
MethodStubVerificator.prototype.times = function (value) { | ||
var allMatchingActions = this.methodToVerify.mock.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var allMatchingActions = this.methodToVerify.mocker.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
if (value !== allMatchingActions.length) { | ||
@@ -32,3 +32,3 @@ var methodToVerifyAsString = this.methodCallToStringConverter.convert(this.methodToVerify); | ||
MethodStubVerificator.prototype.atLeast = function (value) { | ||
var allMatchingActions = this.methodToVerify.mock.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var allMatchingActions = this.methodToVerify.mocker.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
if (value > allMatchingActions.length) { | ||
@@ -40,3 +40,3 @@ var methodToVerifyAsString = this.methodCallToStringConverter.convert(this.methodToVerify); | ||
MethodStubVerificator.prototype.atMost = function (value) { | ||
var allMatchingActions = this.methodToVerify.mock.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var allMatchingActions = this.methodToVerify.mocker.getAllMatchingActions(this.methodToVerify.name, this.methodToVerify.matchers); | ||
if (value < allMatchingActions.length) { | ||
@@ -48,4 +48,4 @@ var methodToVerifyAsString = this.methodCallToStringConverter.convert(this.methodToVerify); | ||
MethodStubVerificator.prototype.calledBefore = function (method) { | ||
var firstMethodAction = this.methodToVerify.mock.getFirstMatchingAction(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var secondMethodAction = method.mock.getFirstMatchingAction(method.name, method.matchers); | ||
var firstMethodAction = this.methodToVerify.mocker.getFirstMatchingAction(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var secondMethodAction = method.mocker.getFirstMatchingAction(method.name, method.matchers); | ||
var mainMethodToVerifyAsString = this.methodCallToStringConverter.convert(this.methodToVerify); | ||
@@ -70,4 +70,4 @@ var secondMethodAsString = this.methodCallToStringConverter.convert(method); | ||
MethodStubVerificator.prototype.calledAfter = function (method) { | ||
var firstMethodAction = this.methodToVerify.mock.getFirstMatchingAction(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var secondMethodAction = method.mock.getFirstMatchingAction(method.name, method.matchers); | ||
var firstMethodAction = this.methodToVerify.mocker.getFirstMatchingAction(this.methodToVerify.name, this.methodToVerify.matchers); | ||
var secondMethodAction = method.mocker.getFirstMatchingAction(method.name, method.matchers); | ||
var mainMethodToVerifyAsString = this.methodCallToStringConverter.convert(this.methodToVerify); | ||
@@ -74,0 +74,0 @@ var secondMethodAsString = this.methodCallToStringConverter.convert(method); |
import { MethodStubCollection } from './MethodStubCollection'; | ||
import { Matcher } from './matcher/type/Matcher'; | ||
import { Mock } from './Mock'; | ||
import { Mocker } from './Mock'; | ||
export declare class MethodToStub { | ||
methodStubCollection: MethodStubCollection; | ||
matchers: Array<Matcher>; | ||
mock: Mock; | ||
mocker: Mocker; | ||
name: string; | ||
constructor(methodStubCollection: MethodStubCollection, matchers: Array<Matcher>, mock: Mock, name: string); | ||
constructor(methodStubCollection: MethodStubCollection, matchers: Array<Matcher>, mocker: Mocker, name: string); | ||
} |
"use strict"; | ||
var MethodToStub = (function () { | ||
function MethodToStub(methodStubCollection, matchers, mock, name) { | ||
function MethodToStub(methodStubCollection, matchers, mocker, name) { | ||
this.methodStubCollection = methodStubCollection; | ||
this.matchers = matchers; | ||
this.mock = mock; | ||
this.mocker = mocker; | ||
this.name = name; | ||
@@ -8,0 +8,0 @@ } |
import { Matcher } from "./matcher/type/Matcher"; | ||
import { MethodAction } from "./MethodAction"; | ||
export declare class Mock { | ||
export declare class Mocker { | ||
private clazz; | ||
@@ -11,2 +11,3 @@ private methodStubCollections; | ||
getMock(): any; | ||
reset(): void; | ||
getAllMatchingActions(methodName: string, matchers: Array<Matcher>): Array<MethodAction>; | ||
@@ -13,0 +14,0 @@ getFirstMatchingAction(methodName: string, matchers: Array<Matcher>): MethodAction; |
@@ -9,4 +9,4 @@ "use strict"; | ||
var ts_mockito_1 = require("./ts-mockito"); | ||
var Mock = (function () { | ||
function Mock(clazz) { | ||
var Mocker = (function () { | ||
function Mocker(clazz) { | ||
this.clazz = clazz; | ||
@@ -18,2 +18,3 @@ this.methodStubCollections = {}; | ||
this.mock.__tsmockitoInstance = this.instance; | ||
this.mock.__tsmockitoMocker = this; | ||
this.createMethodStubsFromPrototypeOwnPropertyNames(); | ||
@@ -28,6 +29,9 @@ this.createMethodStubsFromPrototypeKeys(); | ||
} | ||
Mock.prototype.getMock = function () { | ||
Mocker.prototype.getMock = function () { | ||
return this.mock; | ||
}; | ||
Mock.prototype.getAllMatchingActions = function (methodName, matchers) { | ||
Mocker.prototype.reset = function () { | ||
this.methodActions = []; | ||
}; | ||
Mocker.prototype.getAllMatchingActions = function (methodName, matchers) { | ||
var result = []; | ||
@@ -42,6 +46,6 @@ for (var _i = 0, _a = this.methodActions; _i < _a.length; _i++) { | ||
}; | ||
Mock.prototype.getFirstMatchingAction = function (methodName, matchers) { | ||
Mocker.prototype.getFirstMatchingAction = function (methodName, matchers) { | ||
return this.getAllMatchingActions(methodName, matchers)[0]; | ||
}; | ||
Mock.prototype.createMethodStubsFromPrototypeOwnPropertyNames = function () { | ||
Mocker.prototype.createMethodStubsFromPrototypeOwnPropertyNames = function () { | ||
try { | ||
@@ -56,3 +60,3 @@ var names = Object.getOwnPropertyNames(this.clazz.prototype); | ||
}; | ||
Mock.prototype.createMethodStubsFromPrototypeKeys = function () { | ||
Mocker.prototype.createMethodStubsFromPrototypeKeys = function () { | ||
for (var key in this.clazz.prototype) { | ||
@@ -62,3 +66,3 @@ this.createMethodStub(key); | ||
}; | ||
Mock.prototype.createMethodStubsFromClassCode = function () { | ||
Mocker.prototype.createMethodStubsFromClassCode = function () { | ||
var subKeys = new RedundantMethodNameInCodeFinder_1.RedundantMethodNameInCodeFinder().find(this.clazz.toString()); | ||
@@ -69,3 +73,3 @@ for (var subKey in subKeys) { | ||
}; | ||
Mock.prototype.createMethodStubsFromFunctionsCode = function () { | ||
Mocker.prototype.createMethodStubsFromFunctionsCode = function () { | ||
for (var key in this.clazz.prototype) { | ||
@@ -78,3 +82,3 @@ var subKeys = new RedundantMethodNameInCodeFinder_1.RedundantMethodNameInCodeFinder().find(this.clazz.prototype[key].toString()); | ||
}; | ||
Mock.prototype.createMethodStub = function (key) { | ||
Mocker.prototype.createMethodStub = function (key) { | ||
var _this = this; | ||
@@ -87,3 +91,3 @@ if (this.mock[key]) { | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
args[_i] = arguments[_i]; | ||
} | ||
@@ -106,3 +110,3 @@ if (!_this.methodStubCollections[key]) { | ||
}; | ||
Mock.prototype.createInstanceActionListenersFromPrototypeOwnPropertyNames = function () { | ||
Mocker.prototype.createInstanceActionListenersFromPrototypeOwnPropertyNames = function () { | ||
try { | ||
@@ -117,3 +121,3 @@ var names = Object.getOwnPropertyNames(this.clazz.prototype); | ||
}; | ||
Mock.prototype.createInstanceActionListenersFromPrototypeKeys = function () { | ||
Mocker.prototype.createInstanceActionListenersFromPrototypeKeys = function () { | ||
for (var key in this.clazz.prototype) { | ||
@@ -123,3 +127,3 @@ this.createInstanceActionListener(key); | ||
}; | ||
Mock.prototype.createInstanceActionListenersFromClassCode = function () { | ||
Mocker.prototype.createInstanceActionListenersFromClassCode = function () { | ||
var subKeys = new RedundantMethodNameInCodeFinder_1.RedundantMethodNameInCodeFinder().find(this.clazz.toString()); | ||
@@ -130,3 +134,3 @@ for (var subKey in subKeys) { | ||
}; | ||
Mock.prototype.createInstanceActionListenersFromFunctionsCode = function () { | ||
Mocker.prototype.createInstanceActionListenersFromFunctionsCode = function () { | ||
for (var key in this.clazz.prototype) { | ||
@@ -139,3 +143,3 @@ var subKeys = new RedundantMethodNameInCodeFinder_1.RedundantMethodNameInCodeFinder().find(this.clazz.prototype[key].toString()); | ||
}; | ||
Mock.prototype.createInstanceActionListener = function (key) { | ||
Mocker.prototype.createInstanceActionListener = function (key) { | ||
var _this = this; | ||
@@ -148,3 +152,3 @@ if (this.instance[key]) { | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
args[_i] = arguments[_i]; | ||
} | ||
@@ -158,3 +162,3 @@ var action = new MethodAction_1.MethodAction(key, args); | ||
}; | ||
Mock.prototype.getMethodStub = function (key, args) { | ||
Mocker.prototype.getMethodStub = function (key, args) { | ||
var methodStub = this.methodStubCollections[key]; | ||
@@ -174,5 +178,5 @@ if (!methodStub) { | ||
}; | ||
return Mock; | ||
return Mocker; | ||
}()); | ||
exports.Mock = Mock; | ||
exports.Mocker = Mocker; | ||
//# sourceMappingURL=Mock.js.map |
"use strict"; | ||
var ts_mockito_1 = require('./ts-mockito'); | ||
var ts_mockito_1 = require("./ts-mockito"); | ||
var Generic = (function () { | ||
@@ -11,3 +11,3 @@ function Generic() { | ||
function Temp() { | ||
this.sampleVar = 'test'; | ||
this.sampleVar = "test"; | ||
} | ||
@@ -26,9 +26,9 @@ Temp.prototype.sampleMethod = function (param) { | ||
var myMock = ts_mockito_1.mock(Temp); | ||
ts_mockito_1.when(myMock.sampleMethod(1)).thenReturn('jeden'); | ||
ts_mockito_1.when(myMock.sampleMethod(2)).thenReturn('dwa'); | ||
ts_mockito_1.when(myMock.sampleMethod(3)).thenReturn('trzy'); | ||
ts_mockito_1.when(myMock.sampleMethod2('sampleString', 3)).thenReturn(1); | ||
console.log('>>', ts_mockito_1.instance(myMock).sampleMethod(1)); | ||
console.log('>>', ts_mockito_1.instance(myMock).sampleMethod(2)); | ||
console.log('>>', ts_mockito_1.instance(myMock).sampleMethod(2)); | ||
ts_mockito_1.when(myMock.sampleMethod(1)).thenReturn("jeden"); | ||
ts_mockito_1.when(myMock.sampleMethod(2)).thenReturn("dwa"); | ||
ts_mockito_1.when(myMock.sampleMethod(3)).thenReturn("trzy"); | ||
ts_mockito_1.when(myMock.sampleMethod2("sampleString", 3)).thenReturn(1); | ||
console.log(">>", ts_mockito_1.instance(myMock).sampleMethod(1)); | ||
console.log(">>", ts_mockito_1.instance(myMock).sampleMethod(2)); | ||
console.log(">>", ts_mockito_1.instance(myMock).sampleMethod(2)); | ||
ts_mockito_1.verify(myMock.sampleMethod(ts_mockito_1.anyNumber())).thrice(); | ||
@@ -35,0 +35,0 @@ } |
"use strict"; | ||
var ArgsToMatchersValidator_1 = require('../matcher/ArgsToMatchersValidator'); | ||
var ArgsToMatchersValidator_1 = require("../matcher/ArgsToMatchersValidator"); | ||
var CallFunctionMethodStub = (function () { | ||
@@ -4,0 +4,0 @@ function CallFunctionMethodStub(matchers, func) { |
"use strict"; | ||
var ArgsToMatchersValidator_1 = require('../matcher/ArgsToMatchersValidator'); | ||
var ArgsToMatchersValidator_1 = require("../matcher/ArgsToMatchersValidator"); | ||
var CaptorMethodStub = (function () { | ||
@@ -4,0 +4,0 @@ function CaptorMethodStub(matchers, captors) { |
"use strict"; | ||
var ArgsToMatchersValidator_1 = require('../matcher/ArgsToMatchersValidator'); | ||
var ArgsToMatchersValidator_1 = require("../matcher/ArgsToMatchersValidator"); | ||
var ReturnValueMethodStub = (function () { | ||
@@ -4,0 +4,0 @@ function ReturnValueMethodStub(matchers, returns) { |
"use strict"; | ||
var ArgsToMatchersValidator_1 = require('../matcher/ArgsToMatchersValidator'); | ||
var ArgsToMatchersValidator_1 = require("../matcher/ArgsToMatchersValidator"); | ||
var ThrowErrorMethodStub = (function () { | ||
@@ -4,0 +4,0 @@ function ThrowErrorMethodStub(matchers, error) { |
@@ -11,2 +11,3 @@ import { MethodStubVerificator } from "./MethodStubVerificator"; | ||
export declare function instance<T>(mock: T): T; | ||
export declare function reset<T>(mock: T): void; | ||
export declare function anyNumber(): any; | ||
@@ -13,0 +14,0 @@ export declare function anyString(): any; |
@@ -15,3 +15,3 @@ "use strict"; | ||
function mock(clazz) { | ||
return new Mock_1.Mock(clazz).getMock(); | ||
return new Mock_1.Mocker(clazz).getMock(); | ||
} | ||
@@ -31,2 +31,6 @@ exports.mock = mock; | ||
exports.instance = instance; | ||
function reset(mock) { | ||
mock.__tsmockitoMocker.reset(); | ||
} | ||
exports.reset = reset; | ||
function anyNumber() { | ||
@@ -33,0 +37,0 @@ return new AnyNumberMatcher_1.AnyNumberMatcher(); |
{ | ||
"name": "ts-mockito", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "", | ||
@@ -21,3 +21,3 @@ "main": "lib/ts-mockito.js", | ||
"@types/node": "^6.0.38", | ||
"awesome-typescript-loader": "^2.2.1", | ||
"awesome-typescript-loader": "^3.0.0-beta.17", | ||
"istanbul-instrumenter-loader": "^0.2.0", | ||
@@ -36,3 +36,3 @@ "jasmine-core": "^2.4.1", | ||
"ts-loader": "^0.8.2", | ||
"typescript": "^2.0.0", | ||
"typescript": "^2.1.0", | ||
"webpack": "^1.13.2", | ||
@@ -39,0 +39,0 @@ "webpack-merge": "^0.14.1" |
@@ -1,2 +0,2 @@ | ||
# ts-mockito | ||
# ts-mockito [![build badge](https://travis-ci.org/NagRock/ts-mockito.svg?branch=master)](https://travis-ci.org/NagRock/ts-mockito) | ||
@@ -19,2 +19,3 @@ Mocking library for TypeScript inspired by http://mockito.org/ | ||
* `calledBefore`, `calledAfter` - allows call order verification | ||
* Resetting mock (`reset`) | ||
* Capturing arguments passed to method (`thenCapture`) | ||
@@ -143,2 +144,23 @@ * Recording multiple behaviors | ||
### Resetting mock | ||
``` typescript | ||
// Creating mock | ||
let mockedFoo:Foo = mock(Foo); | ||
// Getting instance | ||
let foo:Foo = instance(mockedFoo); | ||
// Some calls | ||
foo.getBar(1); | ||
foo.getBar(1); | ||
verify(mockedFoo.getBar(1)).twice(); // getBar with arg "1" has been called twice | ||
// Reset mock | ||
reset(mockedFoo); // Reset mock | ||
// Call count verification | ||
verify(mockedFoo.getBar(1)).never(); // has never been called after reset | ||
``` | ||
### Capturing method arguments | ||
@@ -145,0 +167,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76946
1078
255