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,67 +1,67 @@
|
|
|
1
|
-
var sut = require('../expectRequire');
|
|
2
|
-
var test = require('../test');
|
|
3
|
-
var assert = require('assert');
|
|
4
|
-
|
|
5
|
-
var fooFake = {};
|
|
6
|
-
var bazFake = {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(function(){
|
|
10
|
-
console.log('expectRequire');
|
|
11
|
-
|
|
12
|
-
(function() {
|
|
13
|
-
console.log('require');
|
|
14
|
-
sut('./foo').return(fooFake);
|
|
15
|
-
sut('./baz').return(bazFake);
|
|
16
|
-
|
|
17
|
-
var firstReturned = require('./foo');
|
|
18
|
-
var secondReturned = require('./baz');
|
|
19
|
-
var thirdReturned = require('./foo')
|
|
20
|
-
var fourthReturned = require('./baz');
|
|
21
|
-
|
|
22
|
-
test('it should execute returns fooFake first time', function(){
|
|
23
|
-
assert.equal(fooFake,firstReturned);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('it should execute returns bazFake second time', function(){
|
|
27
|
-
assert.equal(bazFake,secondReturned);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('it should execute returns real foo third time', function(){
|
|
31
|
-
assert.notEqual(bazFake,thirdReturned);
|
|
32
|
-
assert.notEqual(fooFake,thirdReturned);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('it should execute returns real foo fourth time', function(){
|
|
36
|
-
assert.notEqual(bazFake,fourthReturned);
|
|
37
|
-
assert.notEqual(fooFake,fourthReturned);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
})();
|
|
41
|
-
|
|
42
|
-
})();
|
|
43
|
-
|
|
44
|
-
(function(){
|
|
45
|
-
console.log('expectRequire reset');
|
|
46
|
-
|
|
47
|
-
(function() {
|
|
48
|
-
console.log('require');
|
|
49
|
-
sut('./foo').return(fooFake);
|
|
50
|
-
sut.reset();
|
|
51
|
-
var returned = require('./foo');
|
|
52
|
-
sut('./foo').return(fooFake);
|
|
53
|
-
var returnedSecond = require('./foo');
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
test('it should execute returns real foo', function(){
|
|
58
|
-
assert.notEqual(fooFake,returned);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('it should execute returns fake foo second time', function(){
|
|
62
|
-
assert.equal(fooFake,returnedSecond);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
})();
|
|
66
|
-
|
|
67
|
-
})();
|
|
1
|
+
var sut = require('../expectRequire');
|
|
2
|
+
var test = require('../test');
|
|
3
|
+
var assert = require('assert');
|
|
4
|
+
|
|
5
|
+
var fooFake = {};
|
|
6
|
+
var bazFake = {};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
(function(){
|
|
10
|
+
console.log('expectRequire');
|
|
11
|
+
|
|
12
|
+
(function() {
|
|
13
|
+
console.log('require');
|
|
14
|
+
sut('./foo').return(fooFake);
|
|
15
|
+
sut('./baz').return(bazFake);
|
|
16
|
+
|
|
17
|
+
var firstReturned = require('./foo');
|
|
18
|
+
var secondReturned = require('./baz');
|
|
19
|
+
var thirdReturned = require('./foo')
|
|
20
|
+
var fourthReturned = require('./baz');
|
|
21
|
+
|
|
22
|
+
test('it should execute returns fooFake first time', function(){
|
|
23
|
+
assert.equal(fooFake,firstReturned);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('it should execute returns bazFake second time', function(){
|
|
27
|
+
assert.equal(bazFake,secondReturned);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('it should execute returns real foo third time', function(){
|
|
31
|
+
assert.notEqual(bazFake,thirdReturned);
|
|
32
|
+
assert.notEqual(fooFake,thirdReturned);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('it should execute returns real foo fourth time', function(){
|
|
36
|
+
assert.notEqual(bazFake,fourthReturned);
|
|
37
|
+
assert.notEqual(fooFake,fourthReturned);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
})();
|
|
43
|
+
|
|
44
|
+
(function(){
|
|
45
|
+
console.log('expectRequire reset');
|
|
46
|
+
|
|
47
|
+
(function() {
|
|
48
|
+
console.log('require');
|
|
49
|
+
sut('./foo').return(fooFake);
|
|
50
|
+
sut.reset();
|
|
51
|
+
var returned = require('./foo');
|
|
52
|
+
sut('./foo').return(fooFake);
|
|
53
|
+
var returnedSecond = require('./foo');
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
test('it should execute returns real foo', function(){
|
|
58
|
+
assert.notEqual(fooFake,returned);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('it should execute returns fake foo second time', function(){
|
|
62
|
+
assert.equal(fooFake,returnedSecond);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
})();
|
|
66
|
+
|
|
67
|
+
})();
|
package/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
require('./util');
|
|
2
|
-
require('./buffer');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
mock: require('./mock'),
|
|
6
|
-
expectRequire: require('./expectRequire'),
|
|
7
|
-
requireMock: require('./requireMock'),
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
1
|
+
require('./util');
|
|
2
|
+
require('./buffer');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
mock: require('./mock'),
|
|
6
|
+
expectRequire: require('./expectRequire'),
|
|
7
|
+
requireMock: require('./requireMock'),
|
|
8
|
+
promise: require('./newThen')
|
|
9
|
+
};
|
package/mock/mockContext.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
function _new(context) {
|
|
2
|
-
if (context)
|
|
3
|
-
return context;
|
|
4
|
-
var verify = require('../newMutableAnd')();
|
|
5
|
-
c = {};
|
|
6
|
-
c.verify = verify;
|
|
7
|
-
return c;
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
function _new(context) {
|
|
2
|
+
if (context)
|
|
3
|
+
return context;
|
|
4
|
+
var verify = require('../newMutableAnd')();
|
|
5
|
+
c = {};
|
|
6
|
+
c.verify = verify;
|
|
7
|
+
return c;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
10
|
module.exports = _new;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var test = require('../../test');
|
|
3
|
-
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
|
-
|
|
5
|
-
(function(){
|
|
6
|
-
console.log('mockContext');
|
|
7
|
-
var newVerify = newRequireMock('../newMutableAnd');
|
|
8
|
-
var sut = require('../mockContext');
|
|
9
|
-
|
|
10
|
-
(function() {
|
|
11
|
-
console.log('empty input.new');
|
|
12
|
-
var verify = {};
|
|
13
|
-
newVerify.expect().return(verify);
|
|
14
|
-
var returned = sut();
|
|
15
|
-
|
|
16
|
-
test('it should set verify', function(){
|
|
17
|
-
assert.equal(returned.verify,verify);
|
|
18
|
-
});
|
|
19
|
-
})();
|
|
20
|
-
|
|
21
|
-
(function() {
|
|
22
|
-
console.log('nonEmpty input.new');
|
|
23
|
-
var input = {};
|
|
24
|
-
var returned = sut(input);
|
|
25
|
-
|
|
26
|
-
test('it should return same', function(){
|
|
27
|
-
assert.equal(returned,input);
|
|
28
|
-
});
|
|
29
|
-
})();
|
|
30
|
-
})();
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var test = require('../../test');
|
|
3
|
+
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
|
+
|
|
5
|
+
(function(){
|
|
6
|
+
console.log('mockContext');
|
|
7
|
+
var newVerify = newRequireMock('../newMutableAnd');
|
|
8
|
+
var sut = require('../mockContext');
|
|
9
|
+
|
|
10
|
+
(function() {
|
|
11
|
+
console.log('empty input.new');
|
|
12
|
+
var verify = {};
|
|
13
|
+
newVerify.expect().return(verify);
|
|
14
|
+
var returned = sut();
|
|
15
|
+
|
|
16
|
+
test('it should set verify', function(){
|
|
17
|
+
assert.equal(returned.verify,verify);
|
|
18
|
+
});
|
|
19
|
+
})();
|
|
20
|
+
|
|
21
|
+
(function() {
|
|
22
|
+
console.log('nonEmpty input.new');
|
|
23
|
+
var input = {};
|
|
24
|
+
var returned = sut(input);
|
|
25
|
+
|
|
26
|
+
test('it should return same', function(){
|
|
27
|
+
assert.equal(returned,input);
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
30
|
+
})();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var propertyMock = require('./propertyMock');
|
|
2
|
-
|
|
3
|
-
function execute(subject,mockObject) {
|
|
4
|
-
if (!(subject instanceof Object))
|
|
5
|
-
return;
|
|
6
|
-
var mockFuncProperties = require('./mockFuncProperties');
|
|
7
|
-
for(var propertyName in subject) {
|
|
8
|
-
var property = subject[propertyName];
|
|
9
|
-
var mockProperty = mockObject[propertyName];
|
|
10
|
-
if (property instanceof Function)
|
|
11
|
-
subject[propertyName] = propertyMock(subject,propertyName,mockProperty);
|
|
12
|
-
mockFuncProperties(property,mockProperty);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = execute;
|
|
1
|
+
var propertyMock = require('./propertyMock');
|
|
2
|
+
|
|
3
|
+
function execute(subject,mockObject) {
|
|
4
|
+
if (!(subject instanceof Object))
|
|
5
|
+
return;
|
|
6
|
+
var mockFuncProperties = require('./mockFuncProperties');
|
|
7
|
+
for(var propertyName in subject) {
|
|
8
|
+
var property = subject[propertyName];
|
|
9
|
+
var mockProperty = mockObject[propertyName];
|
|
10
|
+
if (property instanceof Function)
|
|
11
|
+
subject[propertyName] = propertyMock(subject,propertyName,mockProperty);
|
|
12
|
+
mockFuncProperties(property,mockProperty);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = execute;
|
|
@@ -1,67 +1,67 @@
|
|
|
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('mockFuncProperties');
|
|
8
|
-
var newPropertyMock = newRequireMock('./propertyMock');
|
|
9
|
-
var mockFuncProperties = newRequireMock('./mockFuncProperties');
|
|
10
|
-
var sut = require('../mockFuncProperties');
|
|
11
|
-
|
|
12
|
-
(function() {
|
|
13
|
-
console.log('subject is non-primitive');
|
|
14
|
-
var subject = {};
|
|
15
|
-
var a2 = {};
|
|
16
|
-
var a = function() {};
|
|
17
|
-
var b = {};
|
|
18
|
-
subject.a = a;
|
|
19
|
-
subject.b = b;
|
|
20
|
-
|
|
21
|
-
var mockObject = {};
|
|
22
|
-
var aMock = {};
|
|
23
|
-
var b2Mock = {};
|
|
24
|
-
var bMock = {};
|
|
25
|
-
mockObject.a = aMock;
|
|
26
|
-
mockObject.b = bMock;
|
|
27
|
-
|
|
28
|
-
var expectedA = {};
|
|
29
|
-
newPropertyMock.expect(subject).expect('a').expect(aMock).return(expectedA);
|
|
30
|
-
mockFuncProperties.expect(a).expect(aMock).whenCalled(onMockSubProperties).return();
|
|
31
|
-
mockFuncProperties.expect(b).expect(bMock).whenCalled(onMockSubProperties).return();
|
|
32
|
-
|
|
33
|
-
var mockSubPropertiesCount = 0;
|
|
34
|
-
var didMockSubProperties = false;
|
|
35
|
-
|
|
36
|
-
function onMockSubProperties() {
|
|
37
|
-
mockSubPropertiesCount++;
|
|
38
|
-
didMockSubProperties = (mockSubPropertiesCount == 2);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
sut(subject,mockObject);
|
|
42
|
-
|
|
43
|
-
test('it should mock property a',function() {
|
|
44
|
-
assert.equal(subject.a,expectedA);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('it should mock subProperties',function() {
|
|
48
|
-
assert.ok(didMockSubProperties);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('it should not change property b',function() {
|
|
52
|
-
assert.equal(subject.b,b);
|
|
53
|
-
});
|
|
54
|
-
})();
|
|
55
|
-
|
|
56
|
-
(function() {
|
|
57
|
-
console.log('subject is primitive');
|
|
58
|
-
var subject = 'a';
|
|
59
|
-
var mockObject = 'a';
|
|
60
|
-
|
|
61
|
-
sut(subject,mockObject);
|
|
62
|
-
|
|
63
|
-
test('it should not throw',function() {
|
|
64
|
-
assert(true);
|
|
65
|
-
});
|
|
66
|
-
})();
|
|
67
|
-
})();
|
|
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('mockFuncProperties');
|
|
8
|
+
var newPropertyMock = newRequireMock('./propertyMock');
|
|
9
|
+
var mockFuncProperties = newRequireMock('./mockFuncProperties');
|
|
10
|
+
var sut = require('../mockFuncProperties');
|
|
11
|
+
|
|
12
|
+
(function() {
|
|
13
|
+
console.log('subject is non-primitive');
|
|
14
|
+
var subject = {};
|
|
15
|
+
var a2 = {};
|
|
16
|
+
var a = function() {};
|
|
17
|
+
var b = {};
|
|
18
|
+
subject.a = a;
|
|
19
|
+
subject.b = b;
|
|
20
|
+
|
|
21
|
+
var mockObject = {};
|
|
22
|
+
var aMock = {};
|
|
23
|
+
var b2Mock = {};
|
|
24
|
+
var bMock = {};
|
|
25
|
+
mockObject.a = aMock;
|
|
26
|
+
mockObject.b = bMock;
|
|
27
|
+
|
|
28
|
+
var expectedA = {};
|
|
29
|
+
newPropertyMock.expect(subject).expect('a').expect(aMock).return(expectedA);
|
|
30
|
+
mockFuncProperties.expect(a).expect(aMock).whenCalled(onMockSubProperties).return();
|
|
31
|
+
mockFuncProperties.expect(b).expect(bMock).whenCalled(onMockSubProperties).return();
|
|
32
|
+
|
|
33
|
+
var mockSubPropertiesCount = 0;
|
|
34
|
+
var didMockSubProperties = false;
|
|
35
|
+
|
|
36
|
+
function onMockSubProperties() {
|
|
37
|
+
mockSubPropertiesCount++;
|
|
38
|
+
didMockSubProperties = (mockSubPropertiesCount == 2);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sut(subject,mockObject);
|
|
42
|
+
|
|
43
|
+
test('it should mock property a',function() {
|
|
44
|
+
assert.equal(subject.a,expectedA);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('it should mock subProperties',function() {
|
|
48
|
+
assert.ok(didMockSubProperties);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('it should not change property b',function() {
|
|
52
|
+
assert.equal(subject.b,b);
|
|
53
|
+
});
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
(function() {
|
|
57
|
+
console.log('subject is primitive');
|
|
58
|
+
var subject = 'a';
|
|
59
|
+
var mockObject = 'a';
|
|
60
|
+
|
|
61
|
+
sut(subject,mockObject);
|
|
62
|
+
|
|
63
|
+
test('it should not throw',function() {
|
|
64
|
+
assert(true);
|
|
65
|
+
});
|
|
66
|
+
})();
|
|
67
|
+
})();
|
package/mock/objectMock.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var newMockContext = require('./mockContext');
|
|
2
|
-
var newPartialMock = require('../partialMock');
|
|
3
|
-
|
|
4
|
-
function _new(subject,mockContext) {
|
|
5
|
-
var newObjectMock = require('./objectMock');
|
|
6
|
-
|
|
7
|
-
var mockContext = newMockContext(mockContext);
|
|
8
|
-
var mock = {};
|
|
9
|
-
mock.verify = mockContext.verify;
|
|
10
|
-
if (subject instanceof Function) {
|
|
11
|
-
mock = newPartialMock(subject);
|
|
12
|
-
mockContext.verify.add(mock.verify);
|
|
13
|
-
}
|
|
14
|
-
if (!(subject instanceof Object))
|
|
15
|
-
return mock;
|
|
16
|
-
for(var propertyName in subject) {
|
|
17
|
-
var property = subject[propertyName];
|
|
18
|
-
mock[propertyName] = newObjectMock(property,mockContext);
|
|
19
|
-
}
|
|
20
|
-
return mock;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = _new
|
|
1
|
+
var newMockContext = require('./mockContext');
|
|
2
|
+
var newPartialMock = require('../partialMock');
|
|
3
|
+
|
|
4
|
+
function _new(subject,mockContext) {
|
|
5
|
+
var newObjectMock = require('./objectMock');
|
|
6
|
+
|
|
7
|
+
var mockContext = newMockContext(mockContext);
|
|
8
|
+
var mock = {};
|
|
9
|
+
mock.verify = mockContext.verify;
|
|
10
|
+
if (subject instanceof Function) {
|
|
11
|
+
mock = newPartialMock(subject);
|
|
12
|
+
mockContext.verify.add(mock.verify);
|
|
13
|
+
}
|
|
14
|
+
if (!(subject instanceof Object))
|
|
15
|
+
return mock;
|
|
16
|
+
for(var propertyName in subject) {
|
|
17
|
+
var property = subject[propertyName];
|
|
18
|
+
mock[propertyName] = newObjectMock(property,mockContext);
|
|
19
|
+
}
|
|
20
|
+
return mock;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = _new
|