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,65 +1,65 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../test');
|
|
3
|
-
var mock = require('../partialMock/simple/newMock');
|
|
4
|
-
|
|
5
|
-
(function() {
|
|
6
|
-
console.log('then resolve with a promise');
|
|
7
|
-
|
|
8
|
-
var expected = {};
|
|
9
|
-
var expected2 = {};
|
|
10
|
-
var actual;
|
|
11
|
-
var actual2;
|
|
12
|
-
var expectedRepeated = {};
|
|
13
|
-
var actualRepeated;
|
|
14
|
-
var actualRepeated2;
|
|
15
|
-
|
|
16
|
-
var p = require('../newThen')();
|
|
17
|
-
p.then(function(returned) {
|
|
18
|
-
actual = returned
|
|
19
|
-
return {
|
|
20
|
-
then: function(success, fail) {
|
|
21
|
-
success(expected2);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
}, mock())
|
|
26
|
-
.then(function(returned) {
|
|
27
|
-
actual2 = returned;
|
|
28
|
-
}, mock());
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
p.then(function(returned) {
|
|
32
|
-
actualRepeated = returned;
|
|
33
|
-
return {
|
|
34
|
-
then: function(success, fail) {
|
|
35
|
-
success(expectedRepeated);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}, mock())
|
|
39
|
-
.then(function(returned) {
|
|
40
|
-
actualRepeated2 = returned;
|
|
41
|
-
}, mock());
|
|
42
|
-
|
|
43
|
-
var resturned = p.resolve(expected);
|
|
44
|
-
|
|
45
|
-
test('resolve() returns the promise', function() {
|
|
46
|
-
assert.equal(actual, expected);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('invokes success', function() {
|
|
50
|
-
assert.equal(actual, expected);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('invokes success when chained', function() {
|
|
54
|
-
assert.equal(actual2, expected2);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('invokes success when called again', function() {
|
|
58
|
-
assert.equal(actualRepeated, expected);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('invokes success when called again and chained', function() {
|
|
62
|
-
assert.equal(actualRepeated2, expectedRepeated);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../test');
|
|
3
|
+
var mock = require('../partialMock/simple/newMock');
|
|
4
|
+
|
|
5
|
+
(function() {
|
|
6
|
+
console.log('then resolve with a promise');
|
|
7
|
+
|
|
8
|
+
var expected = {};
|
|
9
|
+
var expected2 = {};
|
|
10
|
+
var actual;
|
|
11
|
+
var actual2;
|
|
12
|
+
var expectedRepeated = {};
|
|
13
|
+
var actualRepeated;
|
|
14
|
+
var actualRepeated2;
|
|
15
|
+
|
|
16
|
+
var p = require('../newThen')();
|
|
17
|
+
p.then(function(returned) {
|
|
18
|
+
actual = returned
|
|
19
|
+
return {
|
|
20
|
+
then: function(success, fail) {
|
|
21
|
+
success(expected2);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
}, mock())
|
|
26
|
+
.then(function(returned) {
|
|
27
|
+
actual2 = returned;
|
|
28
|
+
}, mock());
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
p.then(function(returned) {
|
|
32
|
+
actualRepeated = returned;
|
|
33
|
+
return {
|
|
34
|
+
then: function(success, fail) {
|
|
35
|
+
success(expectedRepeated);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}, mock())
|
|
39
|
+
.then(function(returned) {
|
|
40
|
+
actualRepeated2 = returned;
|
|
41
|
+
}, mock());
|
|
42
|
+
|
|
43
|
+
var resturned = p.resolve(expected);
|
|
44
|
+
|
|
45
|
+
test('resolve() returns the promise', function() {
|
|
46
|
+
assert.equal(actual, expected);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('invokes success', function() {
|
|
50
|
+
assert.equal(actual, expected);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('invokes success when chained', function() {
|
|
54
|
+
assert.equal(actual2, expected2);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('invokes success when called again', function() {
|
|
58
|
+
assert.equal(actualRepeated, expected);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('invokes success when called again and chained', function() {
|
|
62
|
+
assert.equal(actualRepeated2, expectedRepeated);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
})();
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
function _new(times) {
|
|
2
|
-
if (typeof times == 'undefined')
|
|
3
|
-
return returnTrue;
|
|
4
|
-
|
|
5
|
-
function returnTrue() {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
var delegate = returnTrueNTimes;
|
|
10
|
-
|
|
11
|
-
function execute() {
|
|
12
|
-
return delegate();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function returnTrueNTimes() {
|
|
16
|
-
times--;
|
|
17
|
-
if (times === 0)
|
|
18
|
-
delegate = returnFalse;
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function returnFalse() {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return execute;
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
1
|
+
function _new(times) {
|
|
2
|
+
if (typeof times == 'undefined')
|
|
3
|
+
return returnTrue;
|
|
4
|
+
|
|
5
|
+
function returnTrue() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var delegate = returnTrueNTimes;
|
|
10
|
+
|
|
11
|
+
function execute() {
|
|
12
|
+
return delegate();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function returnTrueNTimes() {
|
|
16
|
+
times--;
|
|
17
|
+
if (times === 0)
|
|
18
|
+
delegate = returnFalse;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function returnFalse() {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return execute;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
30
|
module.exports = _new;
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../test');
|
|
3
|
-
var newSut = require('../newTrueNTimesThenFalse');
|
|
4
|
-
|
|
5
|
-
(function(){
|
|
6
|
-
console.log('newTrueNTimesThenFalse');
|
|
7
|
-
|
|
8
|
-
(function() {
|
|
9
|
-
console.log('two times');
|
|
10
|
-
var times = 2;
|
|
11
|
-
var sut = newSut(times);
|
|
12
|
-
|
|
13
|
-
(function(){
|
|
14
|
-
console.log('execute three times');
|
|
15
|
-
var returned = sut();
|
|
16
|
-
var returned2 = sut();
|
|
17
|
-
var returned3 = sut();
|
|
18
|
-
|
|
19
|
-
test('it should return true first time',function() {
|
|
20
|
-
assert.ok(returned);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('it should return true second time',function() {
|
|
24
|
-
assert.ok(returned2);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('it should return false third time',function() {
|
|
28
|
-
assert.equal(false,returned3);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
})();
|
|
32
|
-
|
|
33
|
-
})();
|
|
34
|
-
|
|
35
|
-
(function() {
|
|
36
|
-
console.log('undefined times');
|
|
37
|
-
var sut = newSut();
|
|
38
|
-
|
|
39
|
-
(function(){
|
|
40
|
-
console.log('execute n times');
|
|
41
|
-
var returned = sut();
|
|
42
|
-
var returned2 = sut();
|
|
43
|
-
var returned3 = sut();
|
|
44
|
-
|
|
45
|
-
test('it should return true first time',function() {
|
|
46
|
-
assert.ok(returned);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('it should return true second time',function() {
|
|
50
|
-
assert.ok(returned2);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('it should return true nth time',function() {
|
|
54
|
-
assert.ok(returned3);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
})();
|
|
58
|
-
})();
|
|
59
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../test');
|
|
3
|
+
var newSut = require('../newTrueNTimesThenFalse');
|
|
4
|
+
|
|
5
|
+
(function(){
|
|
6
|
+
console.log('newTrueNTimesThenFalse');
|
|
7
|
+
|
|
8
|
+
(function() {
|
|
9
|
+
console.log('two times');
|
|
10
|
+
var times = 2;
|
|
11
|
+
var sut = newSut(times);
|
|
12
|
+
|
|
13
|
+
(function(){
|
|
14
|
+
console.log('execute three times');
|
|
15
|
+
var returned = sut();
|
|
16
|
+
var returned2 = sut();
|
|
17
|
+
var returned3 = sut();
|
|
18
|
+
|
|
19
|
+
test('it should return true first time',function() {
|
|
20
|
+
assert.ok(returned);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('it should return true second time',function() {
|
|
24
|
+
assert.ok(returned2);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('it should return false third time',function() {
|
|
28
|
+
assert.equal(false,returned3);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
})();
|
|
32
|
+
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
(function() {
|
|
36
|
+
console.log('undefined times');
|
|
37
|
+
var sut = newSut();
|
|
38
|
+
|
|
39
|
+
(function(){
|
|
40
|
+
console.log('execute n times');
|
|
41
|
+
var returned = sut();
|
|
42
|
+
var returned2 = sut();
|
|
43
|
+
var returned3 = sut();
|
|
44
|
+
|
|
45
|
+
test('it should return true first time',function() {
|
|
46
|
+
assert.ok(returned);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('it should return true second time',function() {
|
|
50
|
+
assert.ok(returned2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('it should return true nth time',function() {
|
|
54
|
+
assert.ok(returned3);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
})();
|
|
58
|
+
})();
|
|
59
|
+
})();
|
package/newTrueOnceThenFalse.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
function _new() {
|
|
2
|
-
|
|
3
|
-
var delegate = trueOnce;
|
|
4
|
-
|
|
5
|
-
function execute() {
|
|
6
|
-
return delegate();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function trueOnce() {
|
|
10
|
-
delegate = returnFalse;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function returnFalse() {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return execute;
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
1
|
+
function _new() {
|
|
2
|
+
|
|
3
|
+
var delegate = trueOnce;
|
|
4
|
+
|
|
5
|
+
function execute() {
|
|
6
|
+
return delegate();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function trueOnce() {
|
|
10
|
+
delegate = returnFalse;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function returnFalse() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return execute;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
module.exports = _new;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../test');
|
|
3
|
-
var newSut = require('../newTrueOnceThenFalse');
|
|
4
|
-
|
|
5
|
-
(function(){
|
|
6
|
-
console.log('newTrueOnceThenFalse');
|
|
7
|
-
var sut = newSut();
|
|
8
|
-
|
|
9
|
-
(function() {
|
|
10
|
-
console.log('execute');
|
|
11
|
-
var returned = sut();
|
|
12
|
-
|
|
13
|
-
test('it should return true',function() {
|
|
14
|
-
assert.equal(true,returned);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
(function() {
|
|
18
|
-
console.log('execute');
|
|
19
|
-
var returned = sut();
|
|
20
|
-
test('it should return false',function() {
|
|
21
|
-
assert.equal(false,returned);
|
|
22
|
-
});
|
|
23
|
-
})();
|
|
24
|
-
})();
|
|
25
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../test');
|
|
3
|
+
var newSut = require('../newTrueOnceThenFalse');
|
|
4
|
+
|
|
5
|
+
(function(){
|
|
6
|
+
console.log('newTrueOnceThenFalse');
|
|
7
|
+
var sut = newSut();
|
|
8
|
+
|
|
9
|
+
(function() {
|
|
10
|
+
console.log('execute');
|
|
11
|
+
var returned = sut();
|
|
12
|
+
|
|
13
|
+
test('it should return true',function() {
|
|
14
|
+
assert.equal(true,returned);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
(function() {
|
|
18
|
+
console.log('execute');
|
|
19
|
+
var returned = sut();
|
|
20
|
+
test('it should return false',function() {
|
|
21
|
+
assert.equal(false,returned);
|
|
22
|
+
});
|
|
23
|
+
})();
|
|
24
|
+
})();
|
|
25
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "a_mock",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "a_mock",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"title": "a_mock",
|
|
7
|
+
"description": "Sub package of a. Mocking framework",
|
|
8
|
+
"keywords": ["mock","mocking","partial mock","strict mock","tdd","stub","stubbing","mock require","verify"],
|
|
9
|
+
"dependencies": { },
|
|
10
|
+
"repository" : {
|
|
11
|
+
"type" : "git",
|
|
12
|
+
"url" : "git@github.com:alfateam/a_mock.git"
|
|
13
|
+
}
|
|
14
|
+
}
|
package/partialMock/execute.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
function execute(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrementExpectCount,whenCalledEmitter) {
|
|
2
|
-
var negotiateDecrementExpectCount = require('./negotiateDecrementExpectCount');
|
|
3
|
-
|
|
4
|
-
var index = 6;
|
|
5
|
-
var args = [];
|
|
6
|
-
while(index < arguments.length) {
|
|
7
|
-
args.push(arguments[index]);
|
|
8
|
-
index++;
|
|
9
|
-
}
|
|
10
|
-
if (hasCorrectArguments.apply(null,args)) {
|
|
11
|
-
negotiateDecrementExpectCount(shouldDecrementExpectCount,mockContext);
|
|
12
|
-
whenCalledEmitter.emit.apply(null,args);
|
|
13
|
-
return returnValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return fallback.apply(null,args);
|
|
17
|
-
}
|
|
18
|
-
|
|
1
|
+
function execute(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrementExpectCount,whenCalledEmitter) {
|
|
2
|
+
var negotiateDecrementExpectCount = require('./negotiateDecrementExpectCount');
|
|
3
|
+
|
|
4
|
+
var index = 6;
|
|
5
|
+
var args = [];
|
|
6
|
+
while(index < arguments.length) {
|
|
7
|
+
args.push(arguments[index]);
|
|
8
|
+
index++;
|
|
9
|
+
}
|
|
10
|
+
if (hasCorrectArguments.apply(null,args)) {
|
|
11
|
+
negotiateDecrementExpectCount(shouldDecrementExpectCount,mockContext);
|
|
12
|
+
whenCalledEmitter.emit.apply(null,args);
|
|
13
|
+
return returnValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return fallback.apply(null,args);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
19
|
module.exports = execute;
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newMock = require('../simple/newMock');
|
|
4
|
-
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
-
|
|
6
|
-
(function() {
|
|
7
|
-
console.log('requireExecute');
|
|
8
|
-
|
|
9
|
-
(function(){
|
|
10
|
-
console.log('correct arguments.execute');
|
|
11
|
-
var sut = require('../execute');
|
|
12
|
-
var returnValue = {};
|
|
13
|
-
var fallback = newMock();
|
|
14
|
-
var hasCorrectArguments = newMock();
|
|
15
|
-
var mockContext = {};
|
|
16
|
-
var didEmitWhenCalled;
|
|
17
|
-
var negotiateDecrementExpectCount = newRequireMock('./negotiateDecrementExpectCount');
|
|
18
|
-
var shouldDecrement = {};
|
|
19
|
-
var didDecrement;
|
|
20
|
-
var whenCalledEmitter = {};
|
|
21
|
-
negotiateDecrementExpectCount.expect(shouldDecrement).expect(mockContext).whenCalled(onDecrement).return(null);
|
|
22
|
-
|
|
23
|
-
function onDecrement() {
|
|
24
|
-
didDecrement = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var arg = {};
|
|
28
|
-
var arg2 = {};
|
|
29
|
-
hasCorrectArguments.expect(arg).expect(arg2).return(true);
|
|
30
|
-
mockContext.expectCount = 2;
|
|
31
|
-
stubWhenCalledEmitter()
|
|
32
|
-
|
|
33
|
-
function stubWhenCalledEmitter() {
|
|
34
|
-
var emit = newMock();
|
|
35
|
-
whenCalledEmitter.emit = emit;
|
|
36
|
-
mockContext.whenCalled = whenCalledEmitter;
|
|
37
|
-
emit.expect(arg).expect(arg2).whenCalled(onWhenCalled).return();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function onWhenCalled() {
|
|
41
|
-
didEmitWhenCalled = true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var returned = sut(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrement,whenCalledEmitter,arg,arg2);
|
|
45
|
-
|
|
46
|
-
test('it should emit whenCalled',function() {
|
|
47
|
-
assert.ok(didEmitWhenCalled);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('it should negotiate DecrementExpectCount',function() {
|
|
51
|
-
assert.ok(didDecrement);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('it should return returnValue',function() {
|
|
55
|
-
assert.equal(returnValue,returned);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
})();
|
|
59
|
-
|
|
60
|
-
(function(){
|
|
61
|
-
console.log('incorrect arguments.execute');
|
|
62
|
-
var sut = require('../execute');
|
|
63
|
-
var returnValue = {};
|
|
64
|
-
var whenCalledEmitter = {};
|
|
65
|
-
var fallback = newMock();
|
|
66
|
-
var hasCorrectArguments = newMock();
|
|
67
|
-
var mockContext = {};
|
|
68
|
-
var negotiateDecrementExpectCount = newRequireMock('./negotiateDecrementExpectCount');
|
|
69
|
-
var shouldDecrement;
|
|
70
|
-
|
|
71
|
-
var arg = {};
|
|
72
|
-
var arg2 = {};
|
|
73
|
-
hasCorrectArguments.expect(arg).expect(arg2).return(false);
|
|
74
|
-
var expected = {};
|
|
75
|
-
fallback.expect(arg).expect(arg2).return(expected);
|
|
76
|
-
mockContext.expectCount = 2;
|
|
77
|
-
|
|
78
|
-
var returned = sut(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrement,whenCalledEmitter,arg,arg2);
|
|
79
|
-
|
|
80
|
-
test('it should return result from fallback',function() {
|
|
81
|
-
assert.equal(expected,returned);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newMock = require('../simple/newMock');
|
|
4
|
+
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
+
|
|
6
|
+
(function() {
|
|
7
|
+
console.log('requireExecute');
|
|
8
|
+
|
|
9
|
+
(function(){
|
|
10
|
+
console.log('correct arguments.execute');
|
|
11
|
+
var sut = require('../execute');
|
|
12
|
+
var returnValue = {};
|
|
13
|
+
var fallback = newMock();
|
|
14
|
+
var hasCorrectArguments = newMock();
|
|
15
|
+
var mockContext = {};
|
|
16
|
+
var didEmitWhenCalled;
|
|
17
|
+
var negotiateDecrementExpectCount = newRequireMock('./negotiateDecrementExpectCount');
|
|
18
|
+
var shouldDecrement = {};
|
|
19
|
+
var didDecrement;
|
|
20
|
+
var whenCalledEmitter = {};
|
|
21
|
+
negotiateDecrementExpectCount.expect(shouldDecrement).expect(mockContext).whenCalled(onDecrement).return(null);
|
|
22
|
+
|
|
23
|
+
function onDecrement() {
|
|
24
|
+
didDecrement = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var arg = {};
|
|
28
|
+
var arg2 = {};
|
|
29
|
+
hasCorrectArguments.expect(arg).expect(arg2).return(true);
|
|
30
|
+
mockContext.expectCount = 2;
|
|
31
|
+
stubWhenCalledEmitter()
|
|
32
|
+
|
|
33
|
+
function stubWhenCalledEmitter() {
|
|
34
|
+
var emit = newMock();
|
|
35
|
+
whenCalledEmitter.emit = emit;
|
|
36
|
+
mockContext.whenCalled = whenCalledEmitter;
|
|
37
|
+
emit.expect(arg).expect(arg2).whenCalled(onWhenCalled).return();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function onWhenCalled() {
|
|
41
|
+
didEmitWhenCalled = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var returned = sut(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrement,whenCalledEmitter,arg,arg2);
|
|
45
|
+
|
|
46
|
+
test('it should emit whenCalled',function() {
|
|
47
|
+
assert.ok(didEmitWhenCalled);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('it should negotiate DecrementExpectCount',function() {
|
|
51
|
+
assert.ok(didDecrement);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('it should return returnValue',function() {
|
|
55
|
+
assert.equal(returnValue,returned);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
})();
|
|
59
|
+
|
|
60
|
+
(function(){
|
|
61
|
+
console.log('incorrect arguments.execute');
|
|
62
|
+
var sut = require('../execute');
|
|
63
|
+
var returnValue = {};
|
|
64
|
+
var whenCalledEmitter = {};
|
|
65
|
+
var fallback = newMock();
|
|
66
|
+
var hasCorrectArguments = newMock();
|
|
67
|
+
var mockContext = {};
|
|
68
|
+
var negotiateDecrementExpectCount = newRequireMock('./negotiateDecrementExpectCount');
|
|
69
|
+
var shouldDecrement;
|
|
70
|
+
|
|
71
|
+
var arg = {};
|
|
72
|
+
var arg2 = {};
|
|
73
|
+
hasCorrectArguments.expect(arg).expect(arg2).return(false);
|
|
74
|
+
var expected = {};
|
|
75
|
+
fallback.expect(arg).expect(arg2).return(expected);
|
|
76
|
+
mockContext.expectCount = 2;
|
|
77
|
+
|
|
78
|
+
var returned = sut(returnValue,fallback,hasCorrectArguments,mockContext,shouldDecrement,whenCalledEmitter,arg,arg2);
|
|
79
|
+
|
|
80
|
+
test('it should return result from fallback',function() {
|
|
81
|
+
assert.equal(expected,returned);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
})();
|
|
85
85
|
})();
|
package/partialMock/expect.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
function expect(index,mockContext) {
|
|
2
|
-
var newAreSameArgument = require('./newHasSameArgument');
|
|
3
|
-
var expectCore = require('./expectCore');
|
|
4
|
-
var arg = arguments[2];
|
|
5
|
-
var areSameArgument = newAreSameArgument(arg,index);
|
|
6
|
-
var nextExpect = expectCore(areSameArgument,index,mockContext);
|
|
7
|
-
for (var i = 3; i < arguments.length; i++) {
|
|
8
|
-
var argument = arguments[i];
|
|
9
|
-
nextExpect = nextExpect.expect(argument);
|
|
10
|
-
};
|
|
11
|
-
return nextExpect;
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
function expect(index,mockContext) {
|
|
2
|
+
var newAreSameArgument = require('./newHasSameArgument');
|
|
3
|
+
var expectCore = require('./expectCore');
|
|
4
|
+
var arg = arguments[2];
|
|
5
|
+
var areSameArgument = newAreSameArgument(arg,index);
|
|
6
|
+
var nextExpect = expectCore(areSameArgument,index,mockContext);
|
|
7
|
+
for (var i = 3; i < arguments.length; i++) {
|
|
8
|
+
var argument = arguments[i];
|
|
9
|
+
nextExpect = nextExpect.expect(argument);
|
|
10
|
+
};
|
|
11
|
+
return nextExpect;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
14
|
module.exports = expect;
|