a_mock 1.0.5 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +1 -1
- package/and/newBinaryAnd.js +19 -19
- package/and/newBinaryAndSpec/test.js +67 -67
- package/and/newMonadicAnd.js +19 -19
- package/and/newMonadicAndSpec/test.js +45 -45
- package/and.js +11 -11
- package/andSpec/test.js +35 -35
- package/andSpec/testIntegration.js +24 -24
- package/eventEmitter/add.js +5 -5
- package/eventEmitter/addSpec/test.js +22 -22
- package/eventEmitter/emitterContext.js +7 -7
- package/eventEmitter/emitterContextSpec/test.js +12 -12
- package/eventEmitter/remove.js +11 -11
- package/eventEmitter/removeSpec/test.js +27 -27
- package/eventEmitter/tryAdd.js +7 -7
- package/eventEmitter/tryAddSpec/test.js +43 -43
- package/eventEmitter/tryRemove.js +7 -7
- package/eventEmitter/tryRemoveSpec/test.js +43 -43
- package/eventEmitter.js +42 -42
- package/eventEmitterSpec/test.js +142 -142
- package/expectRequire.js +20 -20
- package/expectRequireSpec/test.js +67 -67
- package/index.d.ts +96 -0
- package/index.js +9 -10
- package/mock/mockContext.js +9 -9
- package/mock/mockContextSpec/test.js +30 -30
- package/mock/mockFuncProperties.js +16 -16
- package/mock/mockFuncPropertiesSpec/test.js +67 -67
- package/mock/objectMock.js +23 -23
- package/mock/objectMockSpec/test.js +123 -123
- package/mock/propertyMock.js +13 -13
- package/mock/propertyMockSpec/test.js +36 -36
- package/mock/throwUnexpectedArguments.js +13 -13
- package/mock/throwUnexpectedArgumentsSpec/test.js +35 -35
- package/mock.js +19 -19
- package/mockSpec/test.js +65 -65
- package/mockSpec/testIntegration.js +102 -102
- package/newMutableAnd.js +18 -18
- package/newMutableAndSpec/test.js +48 -48
- package/newObject.js +4 -4
- package/newThen.js +111 -111
- package/newThenSpec/test.js +11 -11
- package/newThenSpec/testExecute.js +80 -80
- package/newThenSpec/testNoCallback.js +57 -57
- package/newThenSpec/testPreReject.js +51 -51
- package/newThenSpec/testPreRejectAndThrow.js +50 -50
- package/newThenSpec/testPreResolve.js +49 -49
- package/newThenSpec/testPreResolveAndThrow.js +48 -48
- package/newThenSpec/testReject.js +56 -56
- package/newThenSpec/testRejectAndThrow.js +56 -56
- package/newThenSpec/testResolve.js +56 -56
- package/newThenSpec/testResolveAndThrow.js +54 -54
- package/newThenSpec/testResolveWithFailingPromise.js +65 -65
- package/newThenSpec/testResolveWithPromise.js +65 -65
- package/newTrueNTimesThenFalse.js +29 -29
- package/newTrueNTimesThenFalseSpec/test.js +59 -59
- package/newTrueOnceThenFalse.js +21 -21
- package/newTrueOnceThenFalseSpec/test.js +25 -25
- package/package.json +14 -13
- package/partialMock/execute.js +18 -18
- package/partialMock/executeSpec/test.js +84 -84
- package/partialMock/expect.js +13 -13
- package/partialMock/expectAnything.js +51 -51
- package/partialMock/expectAnythingSpec/test.js +167 -167
- package/partialMock/expectArray.js +11 -11
- package/partialMock/expectArraySpec/test.js +36 -36
- package/partialMock/expectCore.js +70 -70
- package/partialMock/expectCoreSpec/test.js +241 -241
- package/partialMock/expectEmpty.js +47 -47
- package/partialMock/expectEmptySpec/test.js +194 -194
- package/partialMock/expectSpec/test.js +45 -45
- package/partialMock/fallbackWrapper/getStackTrace.js +13 -13
- package/partialMock/hasSameArgument/isEqualArg.js +68 -68
- package/partialMock/hasSameArgument/isEqualArgSpec/test.js +283 -283
- package/partialMock/ignore.js +7 -7
- package/partialMock/ignoreSpec/test.js +30 -30
- package/partialMock/mockContext/reset.js +14 -14
- package/partialMock/mockContext/resetSpec/test.js +42 -42
- package/partialMock/negotiateDecrementExpectCount.js +5 -5
- package/partialMock/negotiateDecrementExpectCountSpec/test.js +31 -31
- package/partialMock/negotiateEnd.js +10 -10
- package/partialMock/negotiateEndSpec/test.js +64 -64
- package/partialMock/negotiateIncrementExpectCount.js +5 -5
- package/partialMock/negotiateIncrementExpectCountSpec/test.js +31 -31
- package/partialMock/newExecute.js +21 -21
- package/partialMock/newExecuteSpec/test.js +61 -61
- package/partialMock/newFallbackWrapper.js +30 -30
- package/partialMock/newFallbackWrapperSpec/test.js +70 -70
- package/partialMock/newFallbackWrapperSpec/testWithMockError.js +59 -59
- package/partialMock/newFallbackWrapperSpec/testWithOtherError.js +48 -48
- package/partialMock/newHasArgument.js +9 -9
- package/partialMock/newHasArgumentSpec/test.js +36 -36
- package/partialMock/newHasEqualArgumentArray.js +23 -23
- package/partialMock/newHasEqualArgumentArraySpec/test.js +59 -59
- package/partialMock/newHasNoMoreArguments.js +15 -15
- package/partialMock/newHasNoMoreArgumentsSpec/test.js +64 -64
- package/partialMock/newHasSameArgument.js +11 -11
- package/partialMock/newHasSameArgumentSpec/test.js +80 -80
- package/partialMock/newMockContext.js +12 -12
- package/partialMock/newMockContextSpec/test.js +36 -36
- package/partialMock/newThrow.js +6 -6
- package/partialMock/newThrowSpec/test.js +20 -20
- package/partialMock/return.js +24 -24
- package/partialMock/returnSpec/test.js +106 -106
- package/partialMock/setExecute.js +15 -15
- package/partialMock/setExecuteSpec/test.js +87 -87
- package/partialMock/simple/expectRequire.js +12 -12
- package/partialMock/simple/expectRequireSpec/test.js +41 -41
- package/partialMock/simple/newMock/throwUnexpectedArguments.js +9 -9
- package/partialMock/simple/newMock/throwUnexpectedArgumentsSpec/test.js +23 -23
- package/partialMock/simple/newMock.js +10 -10
- package/partialMock/simple/newMockSpec/test.js +28 -28
- package/partialMock/simple/newPartialMock.js +124 -124
- package/partialMock/simple/newPartialMockSpec/test.js +141 -141
- package/partialMock/simple/newPartialMockSpec/testRepeat.js +63 -63
- package/partialMock/simple/newPartialMockSpec/testWithMultiArgs.js +54 -54
- package/partialMock/simple/newPartialMockSpec/testWithSingleArg.js +116 -116
- package/partialMock/simple/newRequireMock.js +12 -12
- package/partialMock/simple/newRequireMockSpec/test.js +39 -39
- package/partialMock/verify.js +7 -7
- package/partialMock/verifySpec/test.js +37 -37
- package/partialMock.js +70 -70
- package/partialMockSpec/test.js +235 -235
- package/partialMockSpec/testIntegration.js +568 -568
- package/promise.js +10 -10
- package/requireMock.js +14 -14
- package/requireMockSpec/test.js +45 -45
- package/strictMock.js +10 -10
- package/strictMockSpec/test.js +28 -28
- package/test.js +16 -16
- package/util.js +7 -1
- package/.npmignore +0 -1
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
function create(originalFunc) {
|
|
2
|
-
|
|
3
|
-
var candidateMock;
|
|
4
|
-
var mockArray = [];
|
|
5
|
-
var curMock = {};
|
|
6
|
-
var expectedArguments = [];
|
|
7
|
-
curMock.whenCalledEmitter = emitter();
|
|
8
|
-
var _arguments;
|
|
9
|
-
|
|
10
|
-
function emitter() {
|
|
11
|
-
var callback = function() {};
|
|
12
|
-
var c = {};
|
|
13
|
-
|
|
14
|
-
c.setSubscriber = function(subscriber) {
|
|
15
|
-
callback = subscriber;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
c.emit = function() {
|
|
19
|
-
callback.apply(null,_arguments);
|
|
20
|
-
}
|
|
21
|
-
return c;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function mock() {
|
|
25
|
-
_arguments = arguments;
|
|
26
|
-
for(var index = 0;index < mockArray.length;index++) {
|
|
27
|
-
candidateMock = mockArray[index];
|
|
28
|
-
if (correctArgs()) {
|
|
29
|
-
candidateMock.whenCalledEmitter.emit();
|
|
30
|
-
negotiateRemove(index);
|
|
31
|
-
return candidateMock.returnValue;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return originalFunc.apply(null,_arguments);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function negotiateRemove(indexOfMock) {
|
|
38
|
-
if (candidateMock.repeatAny)
|
|
39
|
-
return;
|
|
40
|
-
candidateMock.repeat--;
|
|
41
|
-
if (candidateMock.repeat == 0)
|
|
42
|
-
mockArray.splice(indexOfMock,1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function correctArgs() {
|
|
46
|
-
var expectedArguments = candidateMock.args;
|
|
47
|
-
|
|
48
|
-
var length = expectedArguments.length;
|
|
49
|
-
if (_arguments.length !== length)
|
|
50
|
-
return false;
|
|
51
|
-
for(var index = 0; index < length; index++) {
|
|
52
|
-
if (!expectedArguments[index](_arguments[index])) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
mock.expect = function(argument) {
|
|
60
|
-
if (typeof argument === 'undefined')
|
|
61
|
-
return mock;
|
|
62
|
-
var argumentVerifier = sameArgumentVerifier(argument);
|
|
63
|
-
expectedArguments.push(argumentVerifier);
|
|
64
|
-
return mock;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
function sameArgumentVerifier(argument) {
|
|
68
|
-
function verifyArgument(actualArgument)
|
|
69
|
-
{
|
|
70
|
-
return actualArgument === argument;
|
|
71
|
-
}
|
|
72
|
-
return verifyArgument;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
mock.expectAnything = function() {
|
|
76
|
-
expectedArguments.push(verifyAnyArgument);
|
|
77
|
-
return mock;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function verifyAnyArgument(arg)
|
|
81
|
-
{
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
mock.return = function(returnValue) {
|
|
86
|
-
curMock.returnValue = returnValue;
|
|
87
|
-
curMock.args = expectedArguments;
|
|
88
|
-
curMock.repeat = 1;
|
|
89
|
-
mockArray.push(curMock);
|
|
90
|
-
curMock = {};
|
|
91
|
-
curMock.whenCalledEmitter = emitter();
|
|
92
|
-
expectedArguments = [];
|
|
93
|
-
|
|
94
|
-
return mock;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
mock.repeat = function(times) {
|
|
98
|
-
lastMock().repeat = times-1;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
mock.repeatAny = function() {
|
|
102
|
-
lastMock().repeatAny = true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
mock.whenCalled = function(subscriber) {
|
|
106
|
-
curMock.whenCalledEmitter.setSubscriber(subscriber);
|
|
107
|
-
return mock;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function lastMock() {
|
|
111
|
-
var length = mockArray.length;
|
|
112
|
-
return mockArray[length-1];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
mock.reset = function() {
|
|
116
|
-
mockArray = [];
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return mock;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = create;
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
function create(originalFunc) {
|
|
2
|
+
|
|
3
|
+
var candidateMock;
|
|
4
|
+
var mockArray = [];
|
|
5
|
+
var curMock = {};
|
|
6
|
+
var expectedArguments = [];
|
|
7
|
+
curMock.whenCalledEmitter = emitter();
|
|
8
|
+
var _arguments;
|
|
9
|
+
|
|
10
|
+
function emitter() {
|
|
11
|
+
var callback = function() {};
|
|
12
|
+
var c = {};
|
|
13
|
+
|
|
14
|
+
c.setSubscriber = function(subscriber) {
|
|
15
|
+
callback = subscriber;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
c.emit = function() {
|
|
19
|
+
callback.apply(null,_arguments);
|
|
20
|
+
}
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function mock() {
|
|
25
|
+
_arguments = arguments;
|
|
26
|
+
for(var index = 0;index < mockArray.length;index++) {
|
|
27
|
+
candidateMock = mockArray[index];
|
|
28
|
+
if (correctArgs()) {
|
|
29
|
+
candidateMock.whenCalledEmitter.emit();
|
|
30
|
+
negotiateRemove(index);
|
|
31
|
+
return candidateMock.returnValue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return originalFunc.apply(null,_arguments);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function negotiateRemove(indexOfMock) {
|
|
38
|
+
if (candidateMock.repeatAny)
|
|
39
|
+
return;
|
|
40
|
+
candidateMock.repeat--;
|
|
41
|
+
if (candidateMock.repeat == 0)
|
|
42
|
+
mockArray.splice(indexOfMock,1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function correctArgs() {
|
|
46
|
+
var expectedArguments = candidateMock.args;
|
|
47
|
+
|
|
48
|
+
var length = expectedArguments.length;
|
|
49
|
+
if (_arguments.length !== length)
|
|
50
|
+
return false;
|
|
51
|
+
for(var index = 0; index < length; index++) {
|
|
52
|
+
if (!expectedArguments[index](_arguments[index])) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
mock.expect = function(argument) {
|
|
60
|
+
if (typeof argument === 'undefined')
|
|
61
|
+
return mock;
|
|
62
|
+
var argumentVerifier = sameArgumentVerifier(argument);
|
|
63
|
+
expectedArguments.push(argumentVerifier);
|
|
64
|
+
return mock;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function sameArgumentVerifier(argument) {
|
|
68
|
+
function verifyArgument(actualArgument)
|
|
69
|
+
{
|
|
70
|
+
return actualArgument === argument;
|
|
71
|
+
}
|
|
72
|
+
return verifyArgument;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
mock.expectAnything = function() {
|
|
76
|
+
expectedArguments.push(verifyAnyArgument);
|
|
77
|
+
return mock;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function verifyAnyArgument(arg)
|
|
81
|
+
{
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
mock.return = function(returnValue) {
|
|
86
|
+
curMock.returnValue = returnValue;
|
|
87
|
+
curMock.args = expectedArguments;
|
|
88
|
+
curMock.repeat = 1;
|
|
89
|
+
mockArray.push(curMock);
|
|
90
|
+
curMock = {};
|
|
91
|
+
curMock.whenCalledEmitter = emitter();
|
|
92
|
+
expectedArguments = [];
|
|
93
|
+
|
|
94
|
+
return mock;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
mock.repeat = function(times) {
|
|
98
|
+
lastMock().repeat = times-1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
mock.repeatAny = function() {
|
|
102
|
+
lastMock().repeatAny = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
mock.whenCalled = function(subscriber) {
|
|
106
|
+
curMock.whenCalledEmitter.setSubscriber(subscriber);
|
|
107
|
+
return mock;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function lastMock() {
|
|
111
|
+
var length = mockArray.length;
|
|
112
|
+
return mockArray[length-1];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
mock.reset = function() {
|
|
116
|
+
mockArray = [];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return mock;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = create;
|
|
123
|
+
|
|
124
|
+
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
var newSut = require('../newPartialMock');
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var test = require('../../../test');
|
|
4
|
-
|
|
5
|
-
var originalReturnValue = {orig:''};
|
|
6
|
-
function original() {
|
|
7
|
-
return originalReturnValue;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
var foo ={foo:''};
|
|
11
|
-
var baz = {baz:''};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(function(){
|
|
15
|
-
console.log('partialMockSpec');
|
|
16
|
-
|
|
17
|
-
(function() {
|
|
18
|
-
console.log('expect return foo once');
|
|
19
|
-
|
|
20
|
-
var sut = newSut(original);
|
|
21
|
-
|
|
22
|
-
sut.expect().return(foo);
|
|
23
|
-
|
|
24
|
-
var firstReturned = sut();
|
|
25
|
-
var secondReturned = sut();
|
|
26
|
-
var thirdReturned = sut();
|
|
27
|
-
|
|
28
|
-
test('it should execute returns foo first time', function(){
|
|
29
|
-
assert.equal(foo,firstReturned);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('it should execute returns original second time', function(){
|
|
33
|
-
assert.equal(originalReturnValue,secondReturned);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('it should execute returns original third time', function(){
|
|
37
|
-
assert.equal(originalReturnValue,thirdReturned);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
})();
|
|
41
|
-
|
|
42
|
-
(function() {
|
|
43
|
-
console.log('expect return foo twice');
|
|
44
|
-
var sut = newSut(original);
|
|
45
|
-
sut.expect().return(foo);
|
|
46
|
-
sut.expect().return(foo);
|
|
47
|
-
|
|
48
|
-
var firstReturned = sut();
|
|
49
|
-
var secondReturned = sut();
|
|
50
|
-
var thirdReturned = sut();
|
|
51
|
-
|
|
52
|
-
test('it should execute returns foo first time', function(){
|
|
53
|
-
assert.equal(foo,firstReturned);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('it should execute returns foo second time', function(){
|
|
57
|
-
assert.equal(foo,secondReturned);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('it should execute returns original third time', function(){
|
|
61
|
-
assert.equal(originalReturnValue,thirdReturned);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
})();
|
|
65
|
-
|
|
66
|
-
(function() {
|
|
67
|
-
console.log('expect return after reset');
|
|
68
|
-
var sut = newSut(original);
|
|
69
|
-
sut.expect().return(foo);
|
|
70
|
-
sut.expect().return(foo);
|
|
71
|
-
|
|
72
|
-
var firstReturned = sut();
|
|
73
|
-
sut.reset();
|
|
74
|
-
var secondReturned = sut();
|
|
75
|
-
sut.expect().return(foo);
|
|
76
|
-
var thirdReturned = sut();
|
|
77
|
-
|
|
78
|
-
test('it should execute returns foo first time', function(){
|
|
79
|
-
assert.equal(foo,firstReturned);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('it should execute returns original second time', function(){
|
|
83
|
-
assert.equal(originalReturnValue,secondReturned);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('it should execute returns foo third time', function(){
|
|
87
|
-
assert.equal(foo,thirdReturned);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
})();
|
|
91
|
-
|
|
92
|
-
(function() {
|
|
93
|
-
console.log('expect return foo then baz');
|
|
94
|
-
var sut = newSut(original);
|
|
95
|
-
sut.expect().return(foo);
|
|
96
|
-
sut.expect().return(baz);
|
|
97
|
-
|
|
98
|
-
var firstReturned = sut();
|
|
99
|
-
var secondReturned = sut();
|
|
100
|
-
var thirdReturned = sut();
|
|
101
|
-
|
|
102
|
-
test('it should execute returns foo first time', function(){
|
|
103
|
-
assert.equal(foo,firstReturned);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('it should execute returns baz second time', function(){
|
|
107
|
-
assert.equal(baz,secondReturned);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('it should execute returns original third time', function(){
|
|
111
|
-
assert.equal(originalReturnValue,thirdReturned);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
})();
|
|
115
|
-
|
|
116
|
-
(function() {
|
|
117
|
-
console.log('expect return when argument is undefined.');
|
|
118
|
-
var sut = newSut(original);
|
|
119
|
-
var arg = {};
|
|
120
|
-
var someUndefined;
|
|
121
|
-
sut.expect(arg).expectAnything().return(foo);
|
|
122
|
-
sut.expect().return(baz);
|
|
123
|
-
|
|
124
|
-
var firstReturned = sut(arg);
|
|
125
|
-
var secondReturned = sut(arg,someUndefined);
|
|
126
|
-
var thirdReturned = sut(arg,someUndefined);
|
|
127
|
-
|
|
128
|
-
test('it should execute returns original first time', function(){
|
|
129
|
-
assert.equal(originalReturnValue,firstReturned);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('it should execute returns foo second time', function(){
|
|
133
|
-
assert.equal(foo,secondReturned);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('it should execute returns original third time', function(){
|
|
137
|
-
assert.equal(originalReturnValue,thirdReturned);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
})();
|
|
141
|
-
})();
|
|
1
|
+
var newSut = require('../newPartialMock');
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
var test = require('../../../test');
|
|
4
|
+
|
|
5
|
+
var originalReturnValue = {orig:''};
|
|
6
|
+
function original() {
|
|
7
|
+
return originalReturnValue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var foo ={foo:''};
|
|
11
|
+
var baz = {baz:''};
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
(function(){
|
|
15
|
+
console.log('partialMockSpec');
|
|
16
|
+
|
|
17
|
+
(function() {
|
|
18
|
+
console.log('expect return foo once');
|
|
19
|
+
|
|
20
|
+
var sut = newSut(original);
|
|
21
|
+
|
|
22
|
+
sut.expect().return(foo);
|
|
23
|
+
|
|
24
|
+
var firstReturned = sut();
|
|
25
|
+
var secondReturned = sut();
|
|
26
|
+
var thirdReturned = sut();
|
|
27
|
+
|
|
28
|
+
test('it should execute returns foo first time', function(){
|
|
29
|
+
assert.equal(foo,firstReturned);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('it should execute returns original second time', function(){
|
|
33
|
+
assert.equal(originalReturnValue,secondReturned);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('it should execute returns original third time', function(){
|
|
37
|
+
assert.equal(originalReturnValue,thirdReturned);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
(function() {
|
|
43
|
+
console.log('expect return foo twice');
|
|
44
|
+
var sut = newSut(original);
|
|
45
|
+
sut.expect().return(foo);
|
|
46
|
+
sut.expect().return(foo);
|
|
47
|
+
|
|
48
|
+
var firstReturned = sut();
|
|
49
|
+
var secondReturned = sut();
|
|
50
|
+
var thirdReturned = sut();
|
|
51
|
+
|
|
52
|
+
test('it should execute returns foo first time', function(){
|
|
53
|
+
assert.equal(foo,firstReturned);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('it should execute returns foo second time', function(){
|
|
57
|
+
assert.equal(foo,secondReturned);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('it should execute returns original third time', function(){
|
|
61
|
+
assert.equal(originalReturnValue,thirdReturned);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
})();
|
|
65
|
+
|
|
66
|
+
(function() {
|
|
67
|
+
console.log('expect return after reset');
|
|
68
|
+
var sut = newSut(original);
|
|
69
|
+
sut.expect().return(foo);
|
|
70
|
+
sut.expect().return(foo);
|
|
71
|
+
|
|
72
|
+
var firstReturned = sut();
|
|
73
|
+
sut.reset();
|
|
74
|
+
var secondReturned = sut();
|
|
75
|
+
sut.expect().return(foo);
|
|
76
|
+
var thirdReturned = sut();
|
|
77
|
+
|
|
78
|
+
test('it should execute returns foo first time', function(){
|
|
79
|
+
assert.equal(foo,firstReturned);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('it should execute returns original second time', function(){
|
|
83
|
+
assert.equal(originalReturnValue,secondReturned);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('it should execute returns foo third time', function(){
|
|
87
|
+
assert.equal(foo,thirdReturned);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
})();
|
|
91
|
+
|
|
92
|
+
(function() {
|
|
93
|
+
console.log('expect return foo then baz');
|
|
94
|
+
var sut = newSut(original);
|
|
95
|
+
sut.expect().return(foo);
|
|
96
|
+
sut.expect().return(baz);
|
|
97
|
+
|
|
98
|
+
var firstReturned = sut();
|
|
99
|
+
var secondReturned = sut();
|
|
100
|
+
var thirdReturned = sut();
|
|
101
|
+
|
|
102
|
+
test('it should execute returns foo first time', function(){
|
|
103
|
+
assert.equal(foo,firstReturned);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('it should execute returns baz second time', function(){
|
|
107
|
+
assert.equal(baz,secondReturned);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('it should execute returns original third time', function(){
|
|
111
|
+
assert.equal(originalReturnValue,thirdReturned);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
})();
|
|
115
|
+
|
|
116
|
+
(function() {
|
|
117
|
+
console.log('expect return when argument is undefined.');
|
|
118
|
+
var sut = newSut(original);
|
|
119
|
+
var arg = {};
|
|
120
|
+
var someUndefined;
|
|
121
|
+
sut.expect(arg).expectAnything().return(foo);
|
|
122
|
+
sut.expect().return(baz);
|
|
123
|
+
|
|
124
|
+
var firstReturned = sut(arg);
|
|
125
|
+
var secondReturned = sut(arg,someUndefined);
|
|
126
|
+
var thirdReturned = sut(arg,someUndefined);
|
|
127
|
+
|
|
128
|
+
test('it should execute returns original first time', function(){
|
|
129
|
+
assert.equal(originalReturnValue,firstReturned);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('it should execute returns foo second time', function(){
|
|
133
|
+
assert.equal(foo,secondReturned);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('it should execute returns original third time', function(){
|
|
137
|
+
assert.equal(originalReturnValue,thirdReturned);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
})();
|
|
141
|
+
})();
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
var newSut = require('../newPartialMock');
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var test = require('../../../test');
|
|
4
|
-
var originalReturnValue = {orig:''};
|
|
5
|
-
function original() {
|
|
6
|
-
return originalReturnValue;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
var foo ={foo:''};
|
|
10
|
-
var baz = {baz:''};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(function(){
|
|
14
|
-
console.log('partialMockSpec.repeat.');
|
|
15
|
-
|
|
16
|
-
(function() {
|
|
17
|
-
console.log('expect return foo three times.');
|
|
18
|
-
var sut = newSut(original);
|
|
19
|
-
|
|
20
|
-
sut.expect().return(foo).repeat(3);
|
|
21
|
-
|
|
22
|
-
var firstReturned = sut();
|
|
23
|
-
var secondReturned = sut();
|
|
24
|
-
var thirdReturned = sut();
|
|
25
|
-
|
|
26
|
-
test('it should execute returns foo first time', function(){
|
|
27
|
-
assert.equal(foo,firstReturned);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('it should execute returns foo second time', function(){
|
|
31
|
-
assert.equal(foo,secondReturned);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('it should execute returns original third time', function(){
|
|
35
|
-
assert.equal(originalReturnValue,thirdReturned);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
})();
|
|
39
|
-
|
|
40
|
-
(function() {
|
|
41
|
-
console.log('expect return foo any.');
|
|
42
|
-
var sut = newSut(original);
|
|
43
|
-
|
|
44
|
-
sut.expect().return(foo).repeatAny();
|
|
45
|
-
|
|
46
|
-
var firstReturned = sut();
|
|
47
|
-
var secondReturned = sut();
|
|
48
|
-
var thirdReturned = sut();
|
|
49
|
-
|
|
50
|
-
test('it should execute returns foo first time', function(){
|
|
51
|
-
assert.equal(foo,firstReturned);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('it should execute returns foo second time', function(){
|
|
55
|
-
assert.equal(foo,secondReturned);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('it should execute returns foo third time', function(){
|
|
59
|
-
assert.equal(foo,thirdReturned);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
})();
|
|
63
|
-
})();
|
|
1
|
+
var newSut = require('../newPartialMock');
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
var test = require('../../../test');
|
|
4
|
+
var originalReturnValue = {orig:''};
|
|
5
|
+
function original() {
|
|
6
|
+
return originalReturnValue;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var foo ={foo:''};
|
|
10
|
+
var baz = {baz:''};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
(function(){
|
|
14
|
+
console.log('partialMockSpec.repeat.');
|
|
15
|
+
|
|
16
|
+
(function() {
|
|
17
|
+
console.log('expect return foo three times.');
|
|
18
|
+
var sut = newSut(original);
|
|
19
|
+
|
|
20
|
+
sut.expect().return(foo).repeat(3);
|
|
21
|
+
|
|
22
|
+
var firstReturned = sut();
|
|
23
|
+
var secondReturned = sut();
|
|
24
|
+
var thirdReturned = sut();
|
|
25
|
+
|
|
26
|
+
test('it should execute returns foo first time', function(){
|
|
27
|
+
assert.equal(foo,firstReturned);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('it should execute returns foo second time', function(){
|
|
31
|
+
assert.equal(foo,secondReturned);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('it should execute returns original third time', function(){
|
|
35
|
+
assert.equal(originalReturnValue,thirdReturned);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
})();
|
|
39
|
+
|
|
40
|
+
(function() {
|
|
41
|
+
console.log('expect return foo any.');
|
|
42
|
+
var sut = newSut(original);
|
|
43
|
+
|
|
44
|
+
sut.expect().return(foo).repeatAny();
|
|
45
|
+
|
|
46
|
+
var firstReturned = sut();
|
|
47
|
+
var secondReturned = sut();
|
|
48
|
+
var thirdReturned = sut();
|
|
49
|
+
|
|
50
|
+
test('it should execute returns foo first time', function(){
|
|
51
|
+
assert.equal(foo,firstReturned);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('it should execute returns foo second time', function(){
|
|
55
|
+
assert.equal(foo,secondReturned);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('it should execute returns foo third time', function(){
|
|
59
|
+
assert.equal(foo,thirdReturned);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
})();
|
|
63
|
+
})();
|