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.
Files changed (130) hide show
  1. package/AUTHORS +1 -1
  2. package/and/newBinaryAnd.js +19 -19
  3. package/and/newBinaryAndSpec/test.js +67 -67
  4. package/and/newMonadicAnd.js +19 -19
  5. package/and/newMonadicAndSpec/test.js +45 -45
  6. package/and.js +11 -11
  7. package/andSpec/test.js +35 -35
  8. package/andSpec/testIntegration.js +24 -24
  9. package/eventEmitter/add.js +5 -5
  10. package/eventEmitter/addSpec/test.js +22 -22
  11. package/eventEmitter/emitterContext.js +7 -7
  12. package/eventEmitter/emitterContextSpec/test.js +12 -12
  13. package/eventEmitter/remove.js +11 -11
  14. package/eventEmitter/removeSpec/test.js +27 -27
  15. package/eventEmitter/tryAdd.js +7 -7
  16. package/eventEmitter/tryAddSpec/test.js +43 -43
  17. package/eventEmitter/tryRemove.js +7 -7
  18. package/eventEmitter/tryRemoveSpec/test.js +43 -43
  19. package/eventEmitter.js +42 -42
  20. package/eventEmitterSpec/test.js +142 -142
  21. package/expectRequire.js +20 -20
  22. package/expectRequireSpec/test.js +67 -67
  23. package/index.js +9 -10
  24. package/mock/mockContext.js +9 -9
  25. package/mock/mockContextSpec/test.js +30 -30
  26. package/mock/mockFuncProperties.js +16 -16
  27. package/mock/mockFuncPropertiesSpec/test.js +67 -67
  28. package/mock/objectMock.js +23 -23
  29. package/mock/objectMockSpec/test.js +123 -123
  30. package/mock/propertyMock.js +13 -13
  31. package/mock/propertyMockSpec/test.js +36 -36
  32. package/mock/throwUnexpectedArguments.js +13 -13
  33. package/mock/throwUnexpectedArgumentsSpec/test.js +35 -35
  34. package/mock.js +19 -19
  35. package/mockSpec/test.js +65 -65
  36. package/mockSpec/testIntegration.js +102 -102
  37. package/newMutableAnd.js +18 -18
  38. package/newMutableAndSpec/test.js +48 -48
  39. package/newObject.js +4 -4
  40. package/newThen.js +111 -111
  41. package/newThenSpec/test.js +11 -11
  42. package/newThenSpec/testExecute.js +80 -80
  43. package/newThenSpec/testNoCallback.js +57 -57
  44. package/newThenSpec/testPreReject.js +51 -51
  45. package/newThenSpec/testPreRejectAndThrow.js +50 -50
  46. package/newThenSpec/testPreResolve.js +49 -49
  47. package/newThenSpec/testPreResolveAndThrow.js +48 -48
  48. package/newThenSpec/testReject.js +56 -56
  49. package/newThenSpec/testRejectAndThrow.js +56 -56
  50. package/newThenSpec/testResolve.js +56 -56
  51. package/newThenSpec/testResolveAndThrow.js +54 -54
  52. package/newThenSpec/testResolveWithFailingPromise.js +65 -65
  53. package/newThenSpec/testResolveWithPromise.js +65 -65
  54. package/newTrueNTimesThenFalse.js +29 -29
  55. package/newTrueNTimesThenFalseSpec/test.js +59 -59
  56. package/newTrueOnceThenFalse.js +21 -21
  57. package/newTrueOnceThenFalseSpec/test.js +25 -25
  58. package/package.json +13 -13
  59. package/partialMock/execute.js +18 -18
  60. package/partialMock/executeSpec/test.js +84 -84
  61. package/partialMock/expect.js +13 -13
  62. package/partialMock/expectAnything.js +51 -51
  63. package/partialMock/expectAnythingSpec/test.js +167 -167
  64. package/partialMock/expectArray.js +11 -11
  65. package/partialMock/expectArraySpec/test.js +36 -36
  66. package/partialMock/expectCore.js +70 -59
  67. package/partialMock/expectCoreSpec/test.js +241 -209
  68. package/partialMock/expectEmpty.js +47 -36
  69. package/partialMock/expectEmptySpec/test.js +194 -165
  70. package/partialMock/expectSpec/test.js +45 -45
  71. package/partialMock/fallbackWrapper/getStackTrace.js +13 -13
  72. package/partialMock/hasSameArgument/isEqualArg.js +68 -68
  73. package/partialMock/hasSameArgument/isEqualArgSpec/test.js +283 -283
  74. package/partialMock/ignore.js +7 -7
  75. package/partialMock/ignoreSpec/test.js +30 -30
  76. package/partialMock/mockContext/reset.js +14 -14
  77. package/partialMock/mockContext/resetSpec/test.js +42 -42
  78. package/partialMock/negotiateDecrementExpectCount.js +5 -5
  79. package/partialMock/negotiateDecrementExpectCountSpec/test.js +31 -31
  80. package/partialMock/negotiateEnd.js +10 -10
  81. package/partialMock/negotiateEndSpec/test.js +64 -64
  82. package/partialMock/negotiateIncrementExpectCount.js +5 -5
  83. package/partialMock/negotiateIncrementExpectCountSpec/test.js +31 -31
  84. package/partialMock/newExecute.js +21 -21
  85. package/partialMock/newExecuteSpec/test.js +61 -61
  86. package/partialMock/newFallbackWrapper.js +30 -30
  87. package/partialMock/newFallbackWrapperSpec/test.js +70 -70
  88. package/partialMock/newFallbackWrapperSpec/testWithMockError.js +59 -59
  89. package/partialMock/newFallbackWrapperSpec/testWithOtherError.js +48 -48
  90. package/partialMock/newHasArgument.js +9 -9
  91. package/partialMock/newHasArgumentSpec/test.js +36 -36
  92. package/partialMock/newHasEqualArgumentArray.js +23 -23
  93. package/partialMock/newHasEqualArgumentArraySpec/test.js +59 -59
  94. package/partialMock/newHasNoMoreArguments.js +15 -15
  95. package/partialMock/newHasNoMoreArgumentsSpec/test.js +64 -64
  96. package/partialMock/newHasSameArgument.js +11 -11
  97. package/partialMock/newHasSameArgumentSpec/test.js +80 -80
  98. package/partialMock/newMockContext.js +12 -12
  99. package/partialMock/newMockContextSpec/test.js +36 -36
  100. package/partialMock/newThrow.js +6 -6
  101. package/partialMock/newThrowSpec/test.js +20 -20
  102. package/partialMock/return.js +24 -24
  103. package/partialMock/returnSpec/test.js +106 -106
  104. package/partialMock/setExecute.js +15 -15
  105. package/partialMock/setExecuteSpec/test.js +87 -87
  106. package/partialMock/simple/expectRequire.js +12 -12
  107. package/partialMock/simple/expectRequireSpec/test.js +41 -41
  108. package/partialMock/simple/newMock/throwUnexpectedArguments.js +9 -9
  109. package/partialMock/simple/newMock/throwUnexpectedArgumentsSpec/test.js +23 -23
  110. package/partialMock/simple/newMock.js +10 -10
  111. package/partialMock/simple/newMockSpec/test.js +28 -28
  112. package/partialMock/simple/newPartialMock.js +124 -124
  113. package/partialMock/simple/newPartialMockSpec/test.js +141 -141
  114. package/partialMock/simple/newPartialMockSpec/testRepeat.js +63 -63
  115. package/partialMock/simple/newPartialMockSpec/testWithMultiArgs.js +54 -54
  116. package/partialMock/simple/newPartialMockSpec/testWithSingleArg.js +116 -116
  117. package/partialMock/simple/newRequireMock.js +12 -12
  118. package/partialMock/simple/newRequireMockSpec/test.js +39 -39
  119. package/partialMock/verify.js +7 -7
  120. package/partialMock/verifySpec/test.js +37 -37
  121. package/partialMock.js +70 -70
  122. package/partialMockSpec/test.js +235 -235
  123. package/partialMockSpec/testIntegration.js +568 -485
  124. package/promise.js +10 -10
  125. package/requireMock.js +14 -14
  126. package/requireMockSpec/test.js +45 -45
  127. package/strictMock.js +10 -10
  128. package/strictMockSpec/test.js +28 -28
  129. package/test.js +16 -16
  130. 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
- then: require('./newThen')
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
+ };
@@ -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
+ })();
@@ -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