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,123 +1,123 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
|
-
var newMock = require('../../partialMock/simple/newMock');
|
|
5
|
-
|
|
6
|
-
(function(){
|
|
7
|
-
console.log('objectMock');
|
|
8
|
-
var newMockContext = newRequireMock('./mockContext');
|
|
9
|
-
var newPartialMock = newRequireMock('../partialMock');
|
|
10
|
-
var newSut = require('../objectMock');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(function() {
|
|
14
|
-
console.log('subject is object.new');
|
|
15
|
-
var newObjectMock = newRequireMock('./objectMock');
|
|
16
|
-
var initialMockContext = {}
|
|
17
|
-
var mockContext = {};
|
|
18
|
-
var verify = {};
|
|
19
|
-
mockContext.verify = verify;
|
|
20
|
-
var subject = {};
|
|
21
|
-
var a = {};
|
|
22
|
-
var b = {};
|
|
23
|
-
subject.a = a;
|
|
24
|
-
subject.b = b;
|
|
25
|
-
var aMock = {};
|
|
26
|
-
var bMock = {};
|
|
27
|
-
|
|
28
|
-
newMockContext.expect(initialMockContext).return(mockContext);
|
|
29
|
-
newObjectMock.expect(a).expect(mockContext).return(aMock);
|
|
30
|
-
newObjectMock.expect(b).expect(mockContext).return(bMock);
|
|
31
|
-
|
|
32
|
-
var returned = newSut(subject,initialMockContext);
|
|
33
|
-
|
|
34
|
-
test('it should not return subject', function(){
|
|
35
|
-
assert.notEqual(returned,subject);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('it should mock property a',function() {
|
|
39
|
-
assert.equal(returned.a,aMock);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('it should mock property b',function() {
|
|
43
|
-
assert.equal(returned.a,aMock);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('it should set verify',function() {
|
|
47
|
-
assert.equal(returned.verify,verify);
|
|
48
|
-
});
|
|
49
|
-
})();
|
|
50
|
-
|
|
51
|
-
(function() {
|
|
52
|
-
console.log('subject is func.new');
|
|
53
|
-
var newObjectMock = newRequireMock('./objectMock');
|
|
54
|
-
var initialMockContext = {}
|
|
55
|
-
var mockContext = {};
|
|
56
|
-
var compositeVerify = {};
|
|
57
|
-
compositeVerify.add = newMock();
|
|
58
|
-
mockContext.verify = compositeVerify;
|
|
59
|
-
var subject = function() {};
|
|
60
|
-
var a = {};
|
|
61
|
-
var b = {};
|
|
62
|
-
subject.a = a;
|
|
63
|
-
subject.b = b;
|
|
64
|
-
var aMock = {};
|
|
65
|
-
var bMock = {};
|
|
66
|
-
var partialMock = {};
|
|
67
|
-
var verify = {};
|
|
68
|
-
partialMock.verify = verify;
|
|
69
|
-
var didAddVerifyToComposite;
|
|
70
|
-
|
|
71
|
-
newMockContext.expect(initialMockContext).return(mockContext);
|
|
72
|
-
newObjectMock.expect(a).expect(mockContext).return(aMock);
|
|
73
|
-
newObjectMock.expect(b).expect(mockContext).return(bMock);
|
|
74
|
-
newPartialMock.expect(subject).return(partialMock);
|
|
75
|
-
compositeVerify.add.expect(verify).whenCalled(onAddVerify).return(null);
|
|
76
|
-
|
|
77
|
-
function onAddVerify() {
|
|
78
|
-
didAddVerifyToComposite = true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var returned = newSut(subject,initialMockContext);
|
|
82
|
-
|
|
83
|
-
test('it should return partialMock', function(){
|
|
84
|
-
assert.equal(returned,partialMock);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('it should mock property a',function() {
|
|
88
|
-
assert.equal(returned.a,aMock);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('it should mock property b',function() {
|
|
92
|
-
assert.equal(returned.a,aMock);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('it should add verify to mockContext.verify',function() {
|
|
96
|
-
assert.ok(didAddVerifyToComposite);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
})();
|
|
100
|
-
|
|
101
|
-
(function() {
|
|
102
|
-
console.log('subject is primitive');
|
|
103
|
-
var newObjectMock = newRequireMock('./objectMock');
|
|
104
|
-
var initialMockContext = {}
|
|
105
|
-
var mockContext = {};
|
|
106
|
-
var verify = {};
|
|
107
|
-
mockContext.verify = verify;
|
|
108
|
-
|
|
109
|
-
var subject = 12;
|
|
110
|
-
|
|
111
|
-
newMockContext.expect(initialMockContext).return(mockContext);
|
|
112
|
-
|
|
113
|
-
var returned = newSut(subject,initialMockContext);
|
|
114
|
-
|
|
115
|
-
test('it should return object', function(){
|
|
116
|
-
assert.ok(returned instanceof Object);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('it should set verify',function() {
|
|
120
|
-
assert.equal(returned.verify,verify);
|
|
121
|
-
});
|
|
122
|
-
})();
|
|
123
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
|
+
var newMock = require('../../partialMock/simple/newMock');
|
|
5
|
+
|
|
6
|
+
(function(){
|
|
7
|
+
console.log('objectMock');
|
|
8
|
+
var newMockContext = newRequireMock('./mockContext');
|
|
9
|
+
var newPartialMock = newRequireMock('../partialMock');
|
|
10
|
+
var newSut = require('../objectMock');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
(function() {
|
|
14
|
+
console.log('subject is object.new');
|
|
15
|
+
var newObjectMock = newRequireMock('./objectMock');
|
|
16
|
+
var initialMockContext = {}
|
|
17
|
+
var mockContext = {};
|
|
18
|
+
var verify = {};
|
|
19
|
+
mockContext.verify = verify;
|
|
20
|
+
var subject = {};
|
|
21
|
+
var a = {};
|
|
22
|
+
var b = {};
|
|
23
|
+
subject.a = a;
|
|
24
|
+
subject.b = b;
|
|
25
|
+
var aMock = {};
|
|
26
|
+
var bMock = {};
|
|
27
|
+
|
|
28
|
+
newMockContext.expect(initialMockContext).return(mockContext);
|
|
29
|
+
newObjectMock.expect(a).expect(mockContext).return(aMock);
|
|
30
|
+
newObjectMock.expect(b).expect(mockContext).return(bMock);
|
|
31
|
+
|
|
32
|
+
var returned = newSut(subject,initialMockContext);
|
|
33
|
+
|
|
34
|
+
test('it should not return subject', function(){
|
|
35
|
+
assert.notEqual(returned,subject);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('it should mock property a',function() {
|
|
39
|
+
assert.equal(returned.a,aMock);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('it should mock property b',function() {
|
|
43
|
+
assert.equal(returned.a,aMock);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('it should set verify',function() {
|
|
47
|
+
assert.equal(returned.verify,verify);
|
|
48
|
+
});
|
|
49
|
+
})();
|
|
50
|
+
|
|
51
|
+
(function() {
|
|
52
|
+
console.log('subject is func.new');
|
|
53
|
+
var newObjectMock = newRequireMock('./objectMock');
|
|
54
|
+
var initialMockContext = {}
|
|
55
|
+
var mockContext = {};
|
|
56
|
+
var compositeVerify = {};
|
|
57
|
+
compositeVerify.add = newMock();
|
|
58
|
+
mockContext.verify = compositeVerify;
|
|
59
|
+
var subject = function() {};
|
|
60
|
+
var a = {};
|
|
61
|
+
var b = {};
|
|
62
|
+
subject.a = a;
|
|
63
|
+
subject.b = b;
|
|
64
|
+
var aMock = {};
|
|
65
|
+
var bMock = {};
|
|
66
|
+
var partialMock = {};
|
|
67
|
+
var verify = {};
|
|
68
|
+
partialMock.verify = verify;
|
|
69
|
+
var didAddVerifyToComposite;
|
|
70
|
+
|
|
71
|
+
newMockContext.expect(initialMockContext).return(mockContext);
|
|
72
|
+
newObjectMock.expect(a).expect(mockContext).return(aMock);
|
|
73
|
+
newObjectMock.expect(b).expect(mockContext).return(bMock);
|
|
74
|
+
newPartialMock.expect(subject).return(partialMock);
|
|
75
|
+
compositeVerify.add.expect(verify).whenCalled(onAddVerify).return(null);
|
|
76
|
+
|
|
77
|
+
function onAddVerify() {
|
|
78
|
+
didAddVerifyToComposite = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var returned = newSut(subject,initialMockContext);
|
|
82
|
+
|
|
83
|
+
test('it should return partialMock', function(){
|
|
84
|
+
assert.equal(returned,partialMock);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('it should mock property a',function() {
|
|
88
|
+
assert.equal(returned.a,aMock);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('it should mock property b',function() {
|
|
92
|
+
assert.equal(returned.a,aMock);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('it should add verify to mockContext.verify',function() {
|
|
96
|
+
assert.ok(didAddVerifyToComposite);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
})();
|
|
100
|
+
|
|
101
|
+
(function() {
|
|
102
|
+
console.log('subject is primitive');
|
|
103
|
+
var newObjectMock = newRequireMock('./objectMock');
|
|
104
|
+
var initialMockContext = {}
|
|
105
|
+
var mockContext = {};
|
|
106
|
+
var verify = {};
|
|
107
|
+
mockContext.verify = verify;
|
|
108
|
+
|
|
109
|
+
var subject = 12;
|
|
110
|
+
|
|
111
|
+
newMockContext.expect(initialMockContext).return(mockContext);
|
|
112
|
+
|
|
113
|
+
var returned = newSut(subject,initialMockContext);
|
|
114
|
+
|
|
115
|
+
test('it should return object', function(){
|
|
116
|
+
assert.ok(returned instanceof Object);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('it should set verify',function() {
|
|
120
|
+
assert.equal(returned.verify,verify);
|
|
121
|
+
});
|
|
122
|
+
})();
|
|
123
|
+
})();
|
package/mock/propertyMock.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
function _new(subject,propertyName,mock) {
|
|
2
|
-
|
|
3
|
-
function propertyMock() {
|
|
4
|
-
return mock.apply(null,arguments);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
for(var propertyName in subject) {
|
|
8
|
-
propertyMock[propertyName] = subject[propertyName];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return propertyMock;
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
function _new(subject,propertyName,mock) {
|
|
2
|
+
|
|
3
|
+
function propertyMock() {
|
|
4
|
+
return mock.apply(null,arguments);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
for(var propertyName in subject) {
|
|
8
|
+
propertyMock[propertyName] = subject[propertyName];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return propertyMock;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
14
|
module.exports = _new;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newMock = require('../../partialMock/simple/newMock');
|
|
4
|
-
|
|
5
|
-
(function(){
|
|
6
|
-
console.log('propertyMock.new');
|
|
7
|
-
newSut = require('../propertyMock');
|
|
8
|
-
|
|
9
|
-
var subject = {};
|
|
10
|
-
var a = newMock();
|
|
11
|
-
var a1 = 'a1';
|
|
12
|
-
a.a1 = a1;
|
|
13
|
-
subject.a = a;
|
|
14
|
-
|
|
15
|
-
var mock = newMock();
|
|
16
|
-
|
|
17
|
-
var objectMock = {}
|
|
18
|
-
var sut = newSut(subject,'a',mock);
|
|
19
|
-
|
|
20
|
-
test('it should set subProperties',function() {
|
|
21
|
-
assert.equal(sut.a.a1,a1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
(function() {
|
|
25
|
-
console.log('execute mocked property');
|
|
26
|
-
var mockedValue = {};
|
|
27
|
-
var arg = {};
|
|
28
|
-
mock.expect(arg).return(mockedValue);
|
|
29
|
-
var returned = sut(arg);
|
|
30
|
-
|
|
31
|
-
test('it should return mocked value',function() {
|
|
32
|
-
assert.equal(returned,mockedValue)
|
|
33
|
-
});
|
|
34
|
-
})();
|
|
35
|
-
|
|
36
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newMock = require('../../partialMock/simple/newMock');
|
|
4
|
+
|
|
5
|
+
(function(){
|
|
6
|
+
console.log('propertyMock.new');
|
|
7
|
+
newSut = require('../propertyMock');
|
|
8
|
+
|
|
9
|
+
var subject = {};
|
|
10
|
+
var a = newMock();
|
|
11
|
+
var a1 = 'a1';
|
|
12
|
+
a.a1 = a1;
|
|
13
|
+
subject.a = a;
|
|
14
|
+
|
|
15
|
+
var mock = newMock();
|
|
16
|
+
|
|
17
|
+
var objectMock = {}
|
|
18
|
+
var sut = newSut(subject,'a',mock);
|
|
19
|
+
|
|
20
|
+
test('it should set subProperties',function() {
|
|
21
|
+
assert.equal(sut.a.a1,a1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
(function() {
|
|
25
|
+
console.log('execute mocked property');
|
|
26
|
+
var mockedValue = {};
|
|
27
|
+
var arg = {};
|
|
28
|
+
mock.expect(arg).return(mockedValue);
|
|
29
|
+
var returned = sut(arg);
|
|
30
|
+
|
|
31
|
+
test('it should return mocked value',function() {
|
|
32
|
+
assert.equal(returned,mockedValue)
|
|
33
|
+
});
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
})();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
function throwUnexpectedArguments() {
|
|
2
|
-
var msg = 'Unexpected arguments:'
|
|
3
|
-
|
|
4
|
-
for(var i = 0; i < arguments.length ; i++ )
|
|
5
|
-
{
|
|
6
|
-
msg = msg + ' ' + arguments[i];
|
|
7
|
-
}
|
|
8
|
-
var e = new Error();
|
|
9
|
-
e.name = 'Mock Error';
|
|
10
|
-
e.message = msg + '.';
|
|
11
|
-
throw e;
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
function throwUnexpectedArguments() {
|
|
2
|
+
var msg = 'Unexpected arguments:'
|
|
3
|
+
|
|
4
|
+
for(var i = 0; i < arguments.length ; i++ )
|
|
5
|
+
{
|
|
6
|
+
msg = msg + ' ' + arguments[i];
|
|
7
|
+
}
|
|
8
|
+
var e = new Error();
|
|
9
|
+
e.name = 'Mock Error';
|
|
10
|
+
e.message = msg + '.';
|
|
11
|
+
throw e;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
14
|
module.exports = throwUnexpectedArguments;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var arg1 = 'a';
|
|
4
|
-
var arg2 = {};
|
|
5
|
-
var arg3 = 'c';
|
|
6
|
-
var errorMsg = "Unexpected arguments: a [object Object] c."
|
|
7
|
-
var thrownErrorMsg;
|
|
8
|
-
var thrownName;
|
|
9
|
-
|
|
10
|
-
(function(){
|
|
11
|
-
console.log('throwUnexpectedArguments');
|
|
12
|
-
var sut = require('../throwUnexpectedArguments');
|
|
13
|
-
try {
|
|
14
|
-
sut(arg1,arg2,arg3);
|
|
15
|
-
}
|
|
16
|
-
catch(error) {
|
|
17
|
-
thrownErrorMsg = error.message;
|
|
18
|
-
thrownName = error.name;
|
|
19
|
-
thrownStack = error.stack;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
test('it should throw correct msg', function(){
|
|
23
|
-
assert.equal(errorMsg,thrownErrorMsg);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('it should throw correct name', function(){
|
|
27
|
-
assert.equal('Mock Error',thrownName);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('it should have stack', function(){
|
|
31
|
-
assert.ok(thrownStack);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var arg1 = 'a';
|
|
4
|
+
var arg2 = {};
|
|
5
|
+
var arg3 = 'c';
|
|
6
|
+
var errorMsg = "Unexpected arguments: a [object Object] c."
|
|
7
|
+
var thrownErrorMsg;
|
|
8
|
+
var thrownName;
|
|
9
|
+
|
|
10
|
+
(function(){
|
|
11
|
+
console.log('throwUnexpectedArguments');
|
|
12
|
+
var sut = require('../throwUnexpectedArguments');
|
|
13
|
+
try {
|
|
14
|
+
sut(arg1,arg2,arg3);
|
|
15
|
+
}
|
|
16
|
+
catch(error) {
|
|
17
|
+
thrownErrorMsg = error.message;
|
|
18
|
+
thrownName = error.name;
|
|
19
|
+
thrownStack = error.stack;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
test('it should throw correct msg', function(){
|
|
23
|
+
assert.equal(errorMsg,thrownErrorMsg);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('it should throw correct name', function(){
|
|
27
|
+
assert.equal('Mock Error',thrownName);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('it should have stack', function(){
|
|
31
|
+
assert.ok(thrownStack);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
})();
|
package/mock.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var newStrictMock = require('./strictMock');
|
|
2
|
-
var newObjectMock = require('./mock/objectMock');
|
|
3
|
-
var newPartialMock = require('./partialMock')
|
|
4
|
-
var mockFuncProperties = require('./mock/mockFuncProperties')
|
|
5
|
-
|
|
6
|
-
function create(subject) {
|
|
7
|
-
if (subject == undefined)
|
|
8
|
-
return newStrictMock();
|
|
9
|
-
if (subject instanceof Function)
|
|
10
|
-
return newPartialMock(subject);
|
|
11
|
-
var mock = newObjectMock(subject);
|
|
12
|
-
mockFuncProperties(subject,mock);
|
|
13
|
-
return mock;
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = create;
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
var newStrictMock = require('./strictMock');
|
|
2
|
+
var newObjectMock = require('./mock/objectMock');
|
|
3
|
+
var newPartialMock = require('./partialMock')
|
|
4
|
+
var mockFuncProperties = require('./mock/mockFuncProperties')
|
|
5
|
+
|
|
6
|
+
function create(subject) {
|
|
7
|
+
if (subject == undefined)
|
|
8
|
+
return newStrictMock();
|
|
9
|
+
if (subject instanceof Function)
|
|
10
|
+
return newPartialMock(subject);
|
|
11
|
+
var mock = newObjectMock(subject);
|
|
12
|
+
mockFuncProperties(subject,mock);
|
|
13
|
+
return mock;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = create;
|
|
18
|
+
|
|
19
|
+
|
package/mockSpec/test.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../test');
|
|
3
|
-
var newRequireMock = require('../partialMock/simple/newRequireMock');
|
|
4
|
-
|
|
5
|
-
(function(){
|
|
6
|
-
console.log('mock');
|
|
7
|
-
var newStrictMock = newRequireMock('./strictMock');
|
|
8
|
-
var newObjectMock = newRequireMock('./mock/objectMock');
|
|
9
|
-
var mockFuncProperties = newRequireMock('./mock/mockFuncProperties');
|
|
10
|
-
var newPartialMock = newRequireMock('./partialMock');
|
|
11
|
-
var sut = require('../mock');
|
|
12
|
-
|
|
13
|
-
(function() {
|
|
14
|
-
console.log('object input.new');
|
|
15
|
-
var input = {};
|
|
16
|
-
var objectMock = {};
|
|
17
|
-
var didMockFuncProperties;
|
|
18
|
-
|
|
19
|
-
newObjectMock.expect(input).return(objectMock);
|
|
20
|
-
mockFuncProperties.expect(input).expect(objectMock).whenCalled(onMockFuncProperties).return(null);
|
|
21
|
-
|
|
22
|
-
function onMockFuncProperties() {
|
|
23
|
-
didMockFuncProperties = true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var returned = sut(input);
|
|
28
|
-
|
|
29
|
-
test('it should return expected',function() {
|
|
30
|
-
assert.equal(returned,objectMock);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('it should mock func properties',function() {
|
|
34
|
-
assert.ok(didMockFuncProperties);
|
|
35
|
-
});
|
|
36
|
-
})();
|
|
37
|
-
|
|
38
|
-
(function() {
|
|
39
|
-
console.log('func input.new');
|
|
40
|
-
var expected = {};
|
|
41
|
-
var input = function() {};
|
|
42
|
-
newPartialMock.expect(input).return(expected);
|
|
43
|
-
|
|
44
|
-
var returned = sut(input);
|
|
45
|
-
|
|
46
|
-
test('it shold return expected',function() {
|
|
47
|
-
assert.equal(returned,expected);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
(function() {
|
|
53
|
-
console.log('empty input new');
|
|
54
|
-
var expected = {};
|
|
55
|
-
|
|
56
|
-
newStrictMock.expect().return(expected);
|
|
57
|
-
|
|
58
|
-
var returned = sut();
|
|
59
|
-
|
|
60
|
-
test('it shold return expected',function() {
|
|
61
|
-
assert.equal(returned,expected);
|
|
62
|
-
});
|
|
63
|
-
})();
|
|
64
|
-
|
|
65
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../test');
|
|
3
|
+
var newRequireMock = require('../partialMock/simple/newRequireMock');
|
|
4
|
+
|
|
5
|
+
(function(){
|
|
6
|
+
console.log('mock');
|
|
7
|
+
var newStrictMock = newRequireMock('./strictMock');
|
|
8
|
+
var newObjectMock = newRequireMock('./mock/objectMock');
|
|
9
|
+
var mockFuncProperties = newRequireMock('./mock/mockFuncProperties');
|
|
10
|
+
var newPartialMock = newRequireMock('./partialMock');
|
|
11
|
+
var sut = require('../mock');
|
|
12
|
+
|
|
13
|
+
(function() {
|
|
14
|
+
console.log('object input.new');
|
|
15
|
+
var input = {};
|
|
16
|
+
var objectMock = {};
|
|
17
|
+
var didMockFuncProperties;
|
|
18
|
+
|
|
19
|
+
newObjectMock.expect(input).return(objectMock);
|
|
20
|
+
mockFuncProperties.expect(input).expect(objectMock).whenCalled(onMockFuncProperties).return(null);
|
|
21
|
+
|
|
22
|
+
function onMockFuncProperties() {
|
|
23
|
+
didMockFuncProperties = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var returned = sut(input);
|
|
28
|
+
|
|
29
|
+
test('it should return expected',function() {
|
|
30
|
+
assert.equal(returned,objectMock);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('it should mock func properties',function() {
|
|
34
|
+
assert.ok(didMockFuncProperties);
|
|
35
|
+
});
|
|
36
|
+
})();
|
|
37
|
+
|
|
38
|
+
(function() {
|
|
39
|
+
console.log('func input.new');
|
|
40
|
+
var expected = {};
|
|
41
|
+
var input = function() {};
|
|
42
|
+
newPartialMock.expect(input).return(expected);
|
|
43
|
+
|
|
44
|
+
var returned = sut(input);
|
|
45
|
+
|
|
46
|
+
test('it shold return expected',function() {
|
|
47
|
+
assert.equal(returned,expected);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
(function() {
|
|
53
|
+
console.log('empty input new');
|
|
54
|
+
var expected = {};
|
|
55
|
+
|
|
56
|
+
newStrictMock.expect().return(expected);
|
|
57
|
+
|
|
58
|
+
var returned = sut();
|
|
59
|
+
|
|
60
|
+
test('it shold return expected',function() {
|
|
61
|
+
assert.equal(returned,expected);
|
|
62
|
+
});
|
|
63
|
+
})();
|
|
64
|
+
|
|
65
|
+
})();
|