a_mock 1.0.4 → 2.0.0
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.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 +13 -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 -59
- package/partialMock/expectCoreSpec/test.js +241 -209
- package/partialMock/expectEmpty.js +47 -36
- package/partialMock/expectEmptySpec/test.js +194 -165
- 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 -485
- 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/.npmignore +0 -1
|
@@ -1,165 +1,194 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newMock = require('../simple/newMock');
|
|
4
|
-
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
-
|
|
6
|
-
var _return = newRequireMock('./return');
|
|
7
|
-
var newWhenCalledEmitter = newRequireMock('../eventEmitter');
|
|
8
|
-
var newHasNoMoreArguments = newRequireMock('./newHasNoMoreArguments');
|
|
9
|
-
var newThrow = newRequireMock('./newThrow');
|
|
10
|
-
|
|
11
|
-
var sut = require('../expectEmpty');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(function() {
|
|
15
|
-
console.log('expectEmpty');
|
|
16
|
-
var mockContext = {};
|
|
17
|
-
var compositeAreCorrectArguments = newMock();
|
|
18
|
-
var whenCalledEmitter = {} ;
|
|
19
|
-
var hasCorrectArgument = {};
|
|
20
|
-
var index = 0;
|
|
21
|
-
var didAdd;
|
|
22
|
-
|
|
23
|
-
stubHasNoMoreArguments();
|
|
24
|
-
stubWhenCalledEmitter();
|
|
25
|
-
stubMockContext();
|
|
26
|
-
stubCompositeAreCorrectArguments();
|
|
27
|
-
|
|
28
|
-
function stubHasNoMoreArguments() {
|
|
29
|
-
newHasNoMoreArguments.expect(index).expect(mockContext).return(hasCorrectArgument);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function stubWhenCalledEmitter() {
|
|
33
|
-
newWhenCalledEmitter.expect().return(whenCalledEmitter);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function stubMockContext() {
|
|
37
|
-
mockContext.compositeAreCorrectArguments = compositeAreCorrectArguments;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function stubCompositeAreCorrectArguments() {
|
|
41
|
-
var add = newMock();
|
|
42
|
-
add.expect(hasCorrectArgument).whenCalled(onAdd).return(null);
|
|
43
|
-
compositeAreCorrectArguments.add = add;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function onAdd() {
|
|
47
|
-
didAdd = true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var sut2 = sut(mockContext);
|
|
51
|
-
|
|
52
|
-
test('it should set mockContext.NumberOfArgs to zero',function() {
|
|
53
|
-
assert.ok(mockContext.numberOfArgs === 0);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
test('it should add hasNoMoreArguments to compositeAreCorrectArguments',function() {
|
|
58
|
-
assert.ok(didAdd);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('it should set mockContext.whenCalledEmitter',function() {
|
|
62
|
-
assert.equal(mockContext.whenCalledEmitter,whenCalledEmitter);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
(function() {
|
|
66
|
-
console.log('return');
|
|
67
|
-
var expected = {};
|
|
68
|
-
var arg = {};
|
|
69
|
-
_return.expect(arg).expect(index).expect(mockContext).return(expected);
|
|
70
|
-
var returned = sut2.return(arg);
|
|
71
|
-
|
|
72
|
-
test('it should return expected',function() {
|
|
73
|
-
assert.equal(expected,returned)
|
|
74
|
-
});
|
|
75
|
-
})();
|
|
76
|
-
|
|
77
|
-
(function() {
|
|
78
|
-
console.log('whenCalled');
|
|
79
|
-
var callback = {};
|
|
80
|
-
var expected;
|
|
81
|
-
var add = newMock();
|
|
82
|
-
whenCalledEmitter.add = add;
|
|
83
|
-
var didAddCallback;
|
|
84
|
-
add.expect(callback).whenCalled(onAddCallback).return();
|
|
85
|
-
|
|
86
|
-
function onAddCallback() {
|
|
87
|
-
didAddCallback = true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
mockContext.whenCalledEmitter = whenCalledEmitter;
|
|
91
|
-
|
|
92
|
-
var returned = sut2.whenCalled(callback);
|
|
93
|
-
|
|
94
|
-
test('it should add callback to whenCalledEmitter',function() {
|
|
95
|
-
assert.ok(didAddCallback)
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('it should return self',function() {
|
|
99
|
-
assert.equal(returned,sut2);
|
|
100
|
-
});
|
|
101
|
-
})();
|
|
102
|
-
|
|
103
|
-
(function() {
|
|
104
|
-
console.log('throw');
|
|
105
|
-
var error = {};
|
|
106
|
-
var _throw = {};
|
|
107
|
-
var expected = {};
|
|
108
|
-
newThrow.expect(error).return(_throw);
|
|
109
|
-
sut2.whenCalled = newMock();
|
|
110
|
-
sut2.whenCalled.expect(_throw).return(expected);
|
|
111
|
-
|
|
112
|
-
var returned = sut2.throw(error);
|
|
113
|
-
|
|
114
|
-
test('it should return expected',function() {
|
|
115
|
-
assert.equal(returned,expected);
|
|
116
|
-
});
|
|
117
|
-
})();
|
|
118
|
-
|
|
119
|
-
(function() {
|
|
120
|
-
console.log('repeat');
|
|
121
|
-
var expected = {};
|
|
122
|
-
var times = 2;
|
|
123
|
-
var returnContext = {};
|
|
124
|
-
var repeatMock = newMock();
|
|
125
|
-
_return.expectAnything().expect(0).expect(mockContext).whenCalled(onReturn).return(returnContext);
|
|
126
|
-
|
|
127
|
-
function onReturn(returnValue) {
|
|
128
|
-
if (returnValue !== undefined)
|
|
129
|
-
throw new Error('unexpected argument');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
returnContext.repeat = repeatMock;
|
|
133
|
-
repeatMock.expect(times).return(expected);
|
|
134
|
-
|
|
135
|
-
var returned = sut2.repeat(times);
|
|
136
|
-
|
|
137
|
-
test('should return expected',function() {
|
|
138
|
-
assert.equal(returned,expected)
|
|
139
|
-
});
|
|
140
|
-
})();
|
|
141
|
-
|
|
142
|
-
(function() {
|
|
143
|
-
console.log('repeatAny');
|
|
144
|
-
var expected = {};
|
|
145
|
-
var returnContext = {};
|
|
146
|
-
var repeatMock = newMock();
|
|
147
|
-
_return.expectAnything().expect(0).expect(mockContext).whenCalled(onReturn).return(returnContext);
|
|
148
|
-
|
|
149
|
-
function onReturn(returnValue) {
|
|
150
|
-
if (returnValue !== undefined)
|
|
151
|
-
throw new Error('unexpected argument');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
returnContext.repeatAny = repeatMock;
|
|
155
|
-
repeatMock.expect().return(expected);
|
|
156
|
-
|
|
157
|
-
var returned = sut2.repeatAny();
|
|
158
|
-
|
|
159
|
-
test('should return expected',function() {
|
|
160
|
-
assert.equal(returned,expected)
|
|
161
|
-
});
|
|
162
|
-
})();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newMock = require('../simple/newMock');
|
|
4
|
+
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
+
|
|
6
|
+
var _return = newRequireMock('./return');
|
|
7
|
+
var newWhenCalledEmitter = newRequireMock('../eventEmitter');
|
|
8
|
+
var newHasNoMoreArguments = newRequireMock('./newHasNoMoreArguments');
|
|
9
|
+
var newThrow = newRequireMock('./newThrow');
|
|
10
|
+
var newThen = newRequireMock('../newThen');
|
|
11
|
+
var sut = require('../expectEmpty');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
(function() {
|
|
15
|
+
console.log('expectEmpty');
|
|
16
|
+
var mockContext = {};
|
|
17
|
+
var compositeAreCorrectArguments = newMock();
|
|
18
|
+
var whenCalledEmitter = {} ;
|
|
19
|
+
var hasCorrectArgument = {};
|
|
20
|
+
var index = 0;
|
|
21
|
+
var didAdd;
|
|
22
|
+
|
|
23
|
+
stubHasNoMoreArguments();
|
|
24
|
+
stubWhenCalledEmitter();
|
|
25
|
+
stubMockContext();
|
|
26
|
+
stubCompositeAreCorrectArguments();
|
|
27
|
+
|
|
28
|
+
function stubHasNoMoreArguments() {
|
|
29
|
+
newHasNoMoreArguments.expect(index).expect(mockContext).return(hasCorrectArgument);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function stubWhenCalledEmitter() {
|
|
33
|
+
newWhenCalledEmitter.expect().return(whenCalledEmitter);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function stubMockContext() {
|
|
37
|
+
mockContext.compositeAreCorrectArguments = compositeAreCorrectArguments;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function stubCompositeAreCorrectArguments() {
|
|
41
|
+
var add = newMock();
|
|
42
|
+
add.expect(hasCorrectArgument).whenCalled(onAdd).return(null);
|
|
43
|
+
compositeAreCorrectArguments.add = add;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function onAdd() {
|
|
47
|
+
didAdd = true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var sut2 = sut(mockContext);
|
|
51
|
+
|
|
52
|
+
test('it should set mockContext.NumberOfArgs to zero',function() {
|
|
53
|
+
assert.ok(mockContext.numberOfArgs === 0);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
test('it should add hasNoMoreArguments to compositeAreCorrectArguments',function() {
|
|
58
|
+
assert.ok(didAdd);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('it should set mockContext.whenCalledEmitter',function() {
|
|
62
|
+
assert.equal(mockContext.whenCalledEmitter,whenCalledEmitter);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
(function() {
|
|
66
|
+
console.log('return');
|
|
67
|
+
var expected = {};
|
|
68
|
+
var arg = {};
|
|
69
|
+
_return.expect(arg).expect(index).expect(mockContext).return(expected);
|
|
70
|
+
var returned = sut2.return(arg);
|
|
71
|
+
|
|
72
|
+
test('it should return expected',function() {
|
|
73
|
+
assert.equal(expected,returned)
|
|
74
|
+
});
|
|
75
|
+
})();
|
|
76
|
+
|
|
77
|
+
(function() {
|
|
78
|
+
console.log('whenCalled');
|
|
79
|
+
var callback = {};
|
|
80
|
+
var expected;
|
|
81
|
+
var add = newMock();
|
|
82
|
+
whenCalledEmitter.add = add;
|
|
83
|
+
var didAddCallback;
|
|
84
|
+
add.expect(callback).whenCalled(onAddCallback).return();
|
|
85
|
+
|
|
86
|
+
function onAddCallback() {
|
|
87
|
+
didAddCallback = true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
mockContext.whenCalledEmitter = whenCalledEmitter;
|
|
91
|
+
|
|
92
|
+
var returned = sut2.whenCalled(callback);
|
|
93
|
+
|
|
94
|
+
test('it should add callback to whenCalledEmitter',function() {
|
|
95
|
+
assert.ok(didAddCallback)
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('it should return self',function() {
|
|
99
|
+
assert.equal(returned,sut2);
|
|
100
|
+
});
|
|
101
|
+
})();
|
|
102
|
+
|
|
103
|
+
(function() {
|
|
104
|
+
console.log('throw');
|
|
105
|
+
var error = {};
|
|
106
|
+
var _throw = {};
|
|
107
|
+
var expected = {};
|
|
108
|
+
newThrow.expect(error).return(_throw);
|
|
109
|
+
sut2.whenCalled = newMock();
|
|
110
|
+
sut2.whenCalled.expect(_throw).return(expected);
|
|
111
|
+
|
|
112
|
+
var returned = sut2.throw(error);
|
|
113
|
+
|
|
114
|
+
test('it should return expected',function() {
|
|
115
|
+
assert.equal(returned,expected);
|
|
116
|
+
});
|
|
117
|
+
})();
|
|
118
|
+
|
|
119
|
+
(function() {
|
|
120
|
+
console.log('repeat');
|
|
121
|
+
var expected = {};
|
|
122
|
+
var times = 2;
|
|
123
|
+
var returnContext = {};
|
|
124
|
+
var repeatMock = newMock();
|
|
125
|
+
_return.expectAnything().expect(0).expect(mockContext).whenCalled(onReturn).return(returnContext);
|
|
126
|
+
|
|
127
|
+
function onReturn(returnValue) {
|
|
128
|
+
if (returnValue !== undefined)
|
|
129
|
+
throw new Error('unexpected argument');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
returnContext.repeat = repeatMock;
|
|
133
|
+
repeatMock.expect(times).return(expected);
|
|
134
|
+
|
|
135
|
+
var returned = sut2.repeat(times);
|
|
136
|
+
|
|
137
|
+
test('should return expected',function() {
|
|
138
|
+
assert.equal(returned,expected)
|
|
139
|
+
});
|
|
140
|
+
})();
|
|
141
|
+
|
|
142
|
+
(function() {
|
|
143
|
+
console.log('repeatAny');
|
|
144
|
+
var expected = {};
|
|
145
|
+
var returnContext = {};
|
|
146
|
+
var repeatMock = newMock();
|
|
147
|
+
_return.expectAnything().expect(0).expect(mockContext).whenCalled(onReturn).return(returnContext);
|
|
148
|
+
|
|
149
|
+
function onReturn(returnValue) {
|
|
150
|
+
if (returnValue !== undefined)
|
|
151
|
+
throw new Error('unexpected argument');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
returnContext.repeatAny = repeatMock;
|
|
155
|
+
repeatMock.expect().return(expected);
|
|
156
|
+
|
|
157
|
+
var returned = sut2.repeatAny();
|
|
158
|
+
|
|
159
|
+
test('should return expected',function() {
|
|
160
|
+
assert.equal(returned,expected)
|
|
161
|
+
});
|
|
162
|
+
})();
|
|
163
|
+
|
|
164
|
+
(function() {
|
|
165
|
+
console.log('resolve');
|
|
166
|
+
var expected = {};
|
|
167
|
+
var arg = {};
|
|
168
|
+
newThen.resolve = newMock();
|
|
169
|
+
var promise = {};
|
|
170
|
+
newThen.resolve.expect(arg).return(promise);
|
|
171
|
+
_return.expect(promise).expect(index).expect(mockContext).return(expected);
|
|
172
|
+
var returned = sut2.resolve(arg);
|
|
173
|
+
|
|
174
|
+
test('it should return expected as promise',function() {
|
|
175
|
+
assert.equal(expected,returned)
|
|
176
|
+
});
|
|
177
|
+
})();
|
|
178
|
+
|
|
179
|
+
(function() {
|
|
180
|
+
console.log('reject');
|
|
181
|
+
var expected = {};
|
|
182
|
+
var arg = {};
|
|
183
|
+
newThen.reject = newMock();
|
|
184
|
+
var promise = {};
|
|
185
|
+
newThen.reject.expect(arg).return(promise);
|
|
186
|
+
_return.expect(promise).expect(index).expect(mockContext).return(expected);
|
|
187
|
+
var returned = sut2.reject(arg);
|
|
188
|
+
|
|
189
|
+
test('it should return expected as promise',function() {
|
|
190
|
+
assert.equal(expected,returned)
|
|
191
|
+
});
|
|
192
|
+
})();
|
|
193
|
+
|
|
194
|
+
})();
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newMock = require('../simple/newMock');
|
|
4
|
-
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
-
|
|
6
|
-
var expectCore = newRequireMock('./expectCore');
|
|
7
|
-
var newAreSameArgument = newRequireMock('./newHasSameArgument');
|
|
8
|
-
|
|
9
|
-
var sut = require('../expect');
|
|
10
|
-
|
|
11
|
-
(function() {
|
|
12
|
-
console.log('expect');
|
|
13
|
-
var mockContext = {};
|
|
14
|
-
var areSameArgument = newMock();
|
|
15
|
-
var arg = 'arg';
|
|
16
|
-
var arg2 = 'arg2';
|
|
17
|
-
var index = 0;
|
|
18
|
-
var nextExpect = {};
|
|
19
|
-
var expected = {};
|
|
20
|
-
|
|
21
|
-
stubAreSameArgument();
|
|
22
|
-
stubExpectCore();
|
|
23
|
-
stubNextExpect();
|
|
24
|
-
|
|
25
|
-
function stubAreSameArgument() {
|
|
26
|
-
newAreSameArgument.expect(arg).expect(index).return(areSameArgument);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function stubExpectCore() {
|
|
30
|
-
expectCore.expect(areSameArgument).expect(index).expect(mockContext).return(nextExpect);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function stubNextExpect() {
|
|
34
|
-
var expect = newMock();
|
|
35
|
-
expect.expect(arg2).return(expected);
|
|
36
|
-
nextExpect.expect = expect;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var returned = sut(index,mockContext,arg,arg2);
|
|
40
|
-
|
|
41
|
-
test('it should return expected',function() {
|
|
42
|
-
assert.equal(expected,returned);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newMock = require('../simple/newMock');
|
|
4
|
+
var newRequireMock = require('../simple/newRequireMock');
|
|
5
|
+
|
|
6
|
+
var expectCore = newRequireMock('./expectCore');
|
|
7
|
+
var newAreSameArgument = newRequireMock('./newHasSameArgument');
|
|
8
|
+
|
|
9
|
+
var sut = require('../expect');
|
|
10
|
+
|
|
11
|
+
(function() {
|
|
12
|
+
console.log('expect');
|
|
13
|
+
var mockContext = {};
|
|
14
|
+
var areSameArgument = newMock();
|
|
15
|
+
var arg = 'arg';
|
|
16
|
+
var arg2 = 'arg2';
|
|
17
|
+
var index = 0;
|
|
18
|
+
var nextExpect = {};
|
|
19
|
+
var expected = {};
|
|
20
|
+
|
|
21
|
+
stubAreSameArgument();
|
|
22
|
+
stubExpectCore();
|
|
23
|
+
stubNextExpect();
|
|
24
|
+
|
|
25
|
+
function stubAreSameArgument() {
|
|
26
|
+
newAreSameArgument.expect(arg).expect(index).return(areSameArgument);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function stubExpectCore() {
|
|
30
|
+
expectCore.expect(areSameArgument).expect(index).expect(mockContext).return(nextExpect);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function stubNextExpect() {
|
|
34
|
+
var expect = newMock();
|
|
35
|
+
expect.expect(arg2).return(expected);
|
|
36
|
+
nextExpect.expect = expect;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var returned = sut(index,mockContext,arg,arg2);
|
|
40
|
+
|
|
41
|
+
test('it should return expected',function() {
|
|
42
|
+
assert.equal(expected,returned);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
})();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
module.exports = function getStackTrace() {
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
throw new Error();
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
catch(e) {
|
|
8
|
-
var lines = e.stack.split('\n');
|
|
9
|
-
lines.splice(0,4);
|
|
10
|
-
var stack = lines.join('\n');
|
|
11
|
-
return stack;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
1
|
+
module.exports = function getStackTrace() {
|
|
2
|
+
|
|
3
|
+
try {
|
|
4
|
+
throw new Error();
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
catch(e) {
|
|
8
|
+
var lines = e.stack.split('\n');
|
|
9
|
+
lines.splice(0,4);
|
|
10
|
+
var stack = lines.join('\n');
|
|
11
|
+
return stack;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
var Buffer = require('../../buffer').Buffer;
|
|
2
|
-
var util = require('../../util');
|
|
3
|
-
|
|
4
|
-
function isEqualArg(x, y) {
|
|
5
|
-
if (isValueType(x) || isValueType(y))
|
|
6
|
-
return x === y;
|
|
7
|
-
else if (isArray(x) && isArray(y))
|
|
8
|
-
return isEqualArray(x, y);
|
|
9
|
-
else if (Buffer.isBuffer(x) && Buffer.isBuffer(y)) {
|
|
10
|
-
if (x.length != y.length) return false;
|
|
11
|
-
|
|
12
|
-
for (var i = 0; i < x.length; i++) {
|
|
13
|
-
if (x[i] !== y[i]) return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
} else if (util.isDate(x) && util.isDate(y))
|
|
17
|
-
return x.getTime() === y.getTime();
|
|
18
|
-
|
|
19
|
-
return isEqualStruct(x, y);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isArray(x) {
|
|
23
|
-
if (Array.isArray) {
|
|
24
|
-
return Array.isArray(x);
|
|
25
|
-
}
|
|
26
|
-
return Object.prototype.toString.call(x) === '[object Array]';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isEqualArray(x, y) {
|
|
30
|
-
return x.length == y.length && equalContents();
|
|
31
|
-
|
|
32
|
-
function equalContents() {
|
|
33
|
-
var xElement, yElement;
|
|
34
|
-
for (var i = 0; i < x.length; i++) {
|
|
35
|
-
xElement = x[i];
|
|
36
|
-
yElement = y[i];
|
|
37
|
-
if (!isEqualArg(xElement, yElement))
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function isEqualStruct(x, y) {
|
|
45
|
-
var xLength = Object.keys(x).length;
|
|
46
|
-
var yLength = Object.keys(y).length;
|
|
47
|
-
if (xLength == 0 && yLength == 0)
|
|
48
|
-
return x === y;
|
|
49
|
-
return (xLength == yLength) && equalProperties();
|
|
50
|
-
|
|
51
|
-
function equalProperties() {
|
|
52
|
-
for (var property in x) {
|
|
53
|
-
if (!(property in y))
|
|
54
|
-
return false;
|
|
55
|
-
xPropValue = x[property];
|
|
56
|
-
yPropValue = y[property];
|
|
57
|
-
if (!isEqualArg(xPropValue, yPropValue))
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isValueType(x) {
|
|
65
|
-
return (x === null) || (typeof x !== 'object');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = isEqualArg;
|
|
1
|
+
var Buffer = require('../../buffer').Buffer;
|
|
2
|
+
var util = require('../../util');
|
|
3
|
+
|
|
4
|
+
function isEqualArg(x, y) {
|
|
5
|
+
if (isValueType(x) || isValueType(y))
|
|
6
|
+
return x === y;
|
|
7
|
+
else if (isArray(x) && isArray(y))
|
|
8
|
+
return isEqualArray(x, y);
|
|
9
|
+
else if (Buffer.isBuffer(x) && Buffer.isBuffer(y)) {
|
|
10
|
+
if (x.length != y.length) return false;
|
|
11
|
+
|
|
12
|
+
for (var i = 0; i < x.length; i++) {
|
|
13
|
+
if (x[i] !== y[i]) return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
} else if (util.isDate(x) && util.isDate(y))
|
|
17
|
+
return x.getTime() === y.getTime();
|
|
18
|
+
|
|
19
|
+
return isEqualStruct(x, y);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isArray(x) {
|
|
23
|
+
if (Array.isArray) {
|
|
24
|
+
return Array.isArray(x);
|
|
25
|
+
}
|
|
26
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isEqualArray(x, y) {
|
|
30
|
+
return x.length == y.length && equalContents();
|
|
31
|
+
|
|
32
|
+
function equalContents() {
|
|
33
|
+
var xElement, yElement;
|
|
34
|
+
for (var i = 0; i < x.length; i++) {
|
|
35
|
+
xElement = x[i];
|
|
36
|
+
yElement = y[i];
|
|
37
|
+
if (!isEqualArg(xElement, yElement))
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isEqualStruct(x, y) {
|
|
45
|
+
var xLength = Object.keys(x).length;
|
|
46
|
+
var yLength = Object.keys(y).length;
|
|
47
|
+
if (xLength == 0 && yLength == 0)
|
|
48
|
+
return x === y;
|
|
49
|
+
return (xLength == yLength) && equalProperties();
|
|
50
|
+
|
|
51
|
+
function equalProperties() {
|
|
52
|
+
for (var property in x) {
|
|
53
|
+
if (!(property in y))
|
|
54
|
+
return false;
|
|
55
|
+
xPropValue = x[property];
|
|
56
|
+
yPropValue = y[property];
|
|
57
|
+
if (!isEqualArg(xPropValue, yPropValue))
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isValueType(x) {
|
|
65
|
+
return (x === null) || (typeof x !== 'object');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = isEqualArg;
|