a_mock 2.0.2 → 2.0.3
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/.github/workflows/ci.yml +19 -0
- package/README.md +615 -1
- package/and/newBinaryAndSpec/test.js +1 -7
- package/and/newMonadicAndSpec/test.js +2 -5
- package/andSpec/test.js +1 -4
- package/andSpec/testIntegration.js +1 -2
- package/eventEmitter/addSpec/test.js +2 -4
- package/eventEmitter/emitterContextSpec/test.js +2 -3
- package/eventEmitter/removeSpec/test.js +2 -4
- package/eventEmitter/tryAddSpec/test.js +3 -6
- package/eventEmitter/tryRemoveSpec/test.js +2 -5
- package/eventEmitterSpec/test.js +1 -7
- package/expectRequireSpec/test.js +1 -5
- package/index.d.ts +134 -105
- package/mock/mockContextSpec/test.js +2 -5
- package/mock/mockFuncProperties.js +37 -37
- package/mock/mockFuncPropertiesSpec/test.js +2 -5
- package/mock/objectMock.js +59 -46
- package/mock/objectMockSpec/test.js +10 -11
- package/mock/propertyMockSpec/test.js +2 -4
- package/mock/throwUnexpectedArgumentsSpec/test.js +2 -3
- package/mock.js +8 -8
- package/mockSpec/test.js +1 -5
- package/mockSpec/testIntegration.js +1 -5
- package/newMutableAndSpec/test.js +1 -5
- package/newThenSpec/testExecute.js +1 -5
- package/newThenSpec/testNoCallback.js +1 -3
- package/newThenSpec/testPreReject.js +2 -2
- package/newThenSpec/testPreRejectAndThrow.js +2 -2
- package/newThenSpec/testPreResolve.js +1 -2
- package/newThenSpec/testPreResolveAndThrow.js +2 -2
- package/newThenSpec/testReject.js +2 -2
- package/newThenSpec/testRejectAndThrow.js +2 -2
- package/newThenSpec/testResolve.js +1 -2
- package/newThenSpec/testResolveAndThrow.js +2 -2
- package/newThenSpec/testResolveWithFailingPromise.js +1 -2
- package/newThenSpec/testResolveWithPromise.js +1 -2
- package/newTrueNTimesThenFalseSpec/test.js +1 -6
- package/newTrueOnceThenFalseSpec/test.js +1 -4
- package/package.json +5 -1
- package/partialMock/execute.js +10 -10
- package/partialMock/executeSpec/test.js +1 -4
- package/partialMock/expectAnything.js +3 -1
- package/partialMock/expectAnythingSpec/test.js +2 -8
- package/partialMock/expectArraySpec/test.js +2 -3
- package/partialMock/expectCore.js +3 -1
- package/partialMock/expectCoreSpec/test.js +2 -14
- package/partialMock/expectEmptySpec/test.js +2 -10
- package/partialMock/expectSpec/test.js +2 -3
- package/partialMock/hasSameArgument/isEqualArgSpec/test.js +7 -31
- package/partialMock/ignoreSpec/test.js +2 -3
- package/partialMock/mockContext/reset.js +15 -15
- package/partialMock/mockContext/resetSpec/test.js +4 -4
- package/partialMock/negotiateDecrementExpectCountSpec/test.js +1 -4
- package/partialMock/negotiateEndSpec/test.js +1 -6
- package/partialMock/negotiateIncrementExpectCountSpec/test.js +1 -4
- package/partialMock/newExecute.js +9 -9
- package/partialMock/newExecuteSpec/test.js +2 -6
- package/partialMock/newFallbackWrapper.js +29 -29
- package/partialMock/newFallbackWrapperSpec/test.js +2 -6
- package/partialMock/newFallbackWrapperSpec/testWithMockError.js +2 -4
- package/partialMock/newFallbackWrapperSpec/testWithOtherError.js +2 -5
- package/partialMock/newHasArgumentSpec/test.js +2 -5
- package/partialMock/newHasEqualArgumentArraySpec/test.js +2 -7
- package/partialMock/newHasNoMoreArgumentsSpec/test.js +2 -7
- package/partialMock/newHasSameArgumentSpec/test.js +2 -10
- package/partialMock/newMockContext.js +12 -12
- package/partialMock/newMockContextSpec/test.js +6 -6
- package/partialMock/newThrowSpec/test.js +2 -3
- package/partialMock/returnSpec/test.js +2 -5
- package/partialMock/setExecuteSpec/test.js +2 -3
- package/partialMock/simple/expectRequireSpec/test.js +2 -4
- package/partialMock/simple/newMock/throwUnexpectedArgumentsSpec/test.js +3 -4
- package/partialMock/simple/newMockSpec/test.js +2 -3
- package/partialMock/simple/newPartialMock.js +2 -0
- package/partialMock/simple/newPartialMockSpec/test.js +2 -8
- package/partialMock/simple/newPartialMockSpec/testRepeat.js +2 -5
- package/partialMock/simple/newPartialMockSpec/testWithMultiArgs.js +2 -4
- package/partialMock/simple/newPartialMockSpec/testWithSingleArg.js +2 -7
- package/partialMock/simple/newRequireMockSpec/test.js +2 -3
- package/partialMock/verifySpec/test.js +1 -4
- package/partialMock.js +12 -10
- package/partialMockSpec/test.js +3 -10
- package/partialMockSpec/testIntegration.js +1 -2
- package/readmeSpec/testREADME.js +199 -0
- package/requireMockSpec/test.js +1 -2
- package/strictMockSpec/test.js +1 -2
- package/util.js +7 -7
- package/test.js +0 -17
package/andSpec/test.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../partialMock/simple/newRequireMock');
|
|
4
4
|
var newMock = require('../partialMock/simple/newMock');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
(function(){
|
|
8
|
-
console.log('and');
|
|
9
8
|
var sut = require('../and');
|
|
10
9
|
|
|
11
10
|
(function() {
|
|
12
|
-
console.log('execute');
|
|
13
11
|
var returned = sut();
|
|
14
12
|
|
|
15
13
|
test('it returns true',function() {
|
|
@@ -18,7 +16,6 @@ var newMock = require('../partialMock/simple/newMock');
|
|
|
18
16
|
})();
|
|
19
17
|
|
|
20
18
|
(function() {
|
|
21
|
-
console.log('add');
|
|
22
19
|
var newMonadicAnd = newRequireMock('./and/newMonadicAnd');
|
|
23
20
|
var monadicAnd = {};
|
|
24
21
|
var predicate = {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../partialMock/simple/newRequireMock');
|
|
4
4
|
var newMock = require('../partialMock/simple/newMock');
|
|
5
5
|
|
|
6
6
|
var and = require('../and');
|
|
7
7
|
|
|
8
8
|
(function(){
|
|
9
|
-
console.log('and');
|
|
10
9
|
var arg = {};
|
|
11
10
|
var arg2 = {};
|
|
12
11
|
var predicate1 = newMock();
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var sut = require('../add');
|
|
4
4
|
|
|
5
5
|
(function(){
|
|
6
|
-
console.log('addSpec');
|
|
7
6
|
|
|
8
7
|
(function() {
|
|
9
|
-
console.log('execute');
|
|
10
8
|
var context = {};
|
|
11
9
|
var callbacks = [{}];
|
|
12
10
|
context.callbacks = callbacks;
|
|
@@ -19,4 +17,4 @@ var sut = require('../add');
|
|
|
19
17
|
});
|
|
20
18
|
})();
|
|
21
19
|
|
|
22
|
-
})();
|
|
20
|
+
})();
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newSut = require('../emitterContext');
|
|
4
4
|
|
|
5
5
|
(function(){
|
|
6
|
-
console.log('newEmitterContext');
|
|
7
6
|
var returned = newSut();
|
|
8
7
|
|
|
9
8
|
test('it should set callbacks to empty array',function() {
|
|
10
9
|
assert.equal(returned.callbacks.length,0);
|
|
11
10
|
});
|
|
12
|
-
})();
|
|
11
|
+
})();
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var sut = require('../remove');
|
|
4
4
|
|
|
5
5
|
(function(){
|
|
6
|
-
console.log('removeSpec');
|
|
7
6
|
|
|
8
7
|
(function() {
|
|
9
|
-
console.log('execute');
|
|
10
8
|
var context = {};
|
|
11
9
|
var callback = {};
|
|
12
10
|
var callback0 = {};
|
|
@@ -24,4 +22,4 @@ var sut = require('../remove');
|
|
|
24
22
|
});
|
|
25
23
|
})();
|
|
26
24
|
|
|
27
|
-
})();
|
|
25
|
+
})();
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
|
-
|
|
4
|
+
var context = {};
|
|
5
5
|
var sut = require('../tryAdd');
|
|
6
6
|
|
|
7
7
|
(function(){
|
|
8
|
-
console.log('tryAddSpec');
|
|
9
8
|
|
|
10
9
|
(function() {
|
|
11
|
-
console.log('execute');
|
|
12
10
|
var add = newRequireMock('./add');
|
|
13
11
|
var didAdd;
|
|
14
12
|
var callback = {};
|
|
@@ -25,7 +23,6 @@ var sut = require('../tryAdd');
|
|
|
25
23
|
});
|
|
26
24
|
|
|
27
25
|
(function() {
|
|
28
|
-
console.log('execute with missing callback');
|
|
29
26
|
var add = newRequireMock('./add');
|
|
30
27
|
var didAdd;
|
|
31
28
|
var callback;
|
|
@@ -40,4 +37,4 @@ var sut = require('../tryAdd');
|
|
|
40
37
|
assert.ok(true);
|
|
41
38
|
});
|
|
42
39
|
})();
|
|
43
|
-
})();
|
|
40
|
+
})();
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
4
|
var context = {};
|
|
5
5
|
var sut = require('../tryRemove');
|
|
6
6
|
|
|
7
7
|
(function(){
|
|
8
|
-
console.log('tryRemoveSpec');
|
|
9
8
|
|
|
10
9
|
(function() {
|
|
11
|
-
console.log('execute');
|
|
12
10
|
var remove = newRequireMock('./remove');
|
|
13
11
|
var didremove;
|
|
14
12
|
var callback = {};
|
|
@@ -25,7 +23,6 @@ var sut = require('../tryRemove');
|
|
|
25
23
|
})();
|
|
26
24
|
|
|
27
25
|
(function() {
|
|
28
|
-
console.log('execute with missing callback');
|
|
29
26
|
var remove = newRequireMock('./remove');
|
|
30
27
|
var didremove;
|
|
31
28
|
var callback;
|
|
@@ -40,4 +37,4 @@ var sut = require('../tryRemove');
|
|
|
40
37
|
assert.ok(true);
|
|
41
38
|
});
|
|
42
39
|
})();
|
|
43
|
-
})();
|
|
40
|
+
})();
|
package/eventEmitterSpec/test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test')
|
|
3
3
|
var newRequireMock = require('../partialMock/simple/newRequireMock');
|
|
4
4
|
var newMock = require('../partialMock/simple/newMock');
|
|
5
5
|
|
|
@@ -13,13 +13,11 @@ var tryRemove = newRequireMock('./eventEmitter/tryRemove');
|
|
|
13
13
|
var newSut = require('../eventEmitter');
|
|
14
14
|
|
|
15
15
|
(function(){
|
|
16
|
-
console.log('newEventEmitter');
|
|
17
16
|
var context = {};
|
|
18
17
|
newEmitterContext.expect().return(context);
|
|
19
18
|
var sut = newSut();
|
|
20
19
|
|
|
21
20
|
(function() {
|
|
22
|
-
console.log('add');
|
|
23
21
|
var callback = {};
|
|
24
22
|
var didAdd;
|
|
25
23
|
add.expect(context).expect(callback).whenCalled(onAdd).return();
|
|
@@ -40,7 +38,6 @@ var newSut = require('../eventEmitter');
|
|
|
40
38
|
})();
|
|
41
39
|
|
|
42
40
|
(function() {
|
|
43
|
-
console.log('tryAdd');
|
|
44
41
|
var callback = {};
|
|
45
42
|
var didAdd;
|
|
46
43
|
tryAdd.expect(context).expect(callback).whenCalled(onAdd).return();
|
|
@@ -61,7 +58,6 @@ var newSut = require('../eventEmitter');
|
|
|
61
58
|
})();
|
|
62
59
|
|
|
63
60
|
(function() {
|
|
64
|
-
console.log('remove');
|
|
65
61
|
var callback = {};
|
|
66
62
|
var didRemove;
|
|
67
63
|
remove.expect(context).expect(callback).whenCalled(onRemove).return();
|
|
@@ -82,7 +78,6 @@ var newSut = require('../eventEmitter');
|
|
|
82
78
|
})();
|
|
83
79
|
|
|
84
80
|
(function() {
|
|
85
|
-
console.log('tryRemove');
|
|
86
81
|
var callback = {};
|
|
87
82
|
var didtryRemove;
|
|
88
83
|
tryRemove.expect(context).expect(callback).whenCalled(ontryRemove).return();
|
|
@@ -103,7 +98,6 @@ var newSut = require('../eventEmitter');
|
|
|
103
98
|
})();
|
|
104
99
|
|
|
105
100
|
(function() {
|
|
106
|
-
console.log('emit');
|
|
107
101
|
var callback = {};
|
|
108
102
|
var didemit;
|
|
109
103
|
var callback = newMock();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var sut = require('../expectRequire');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var assert = require('assert');
|
|
4
4
|
|
|
5
5
|
var fooFake = {};
|
|
@@ -7,10 +7,8 @@ var bazFake = {};
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
(function(){
|
|
10
|
-
console.log('expectRequire');
|
|
11
10
|
|
|
12
11
|
(function() {
|
|
13
|
-
console.log('require');
|
|
14
12
|
sut('./foo').return(fooFake);
|
|
15
13
|
sut('./baz').return(bazFake);
|
|
16
14
|
|
|
@@ -42,10 +40,8 @@ var bazFake = {};
|
|
|
42
40
|
})();
|
|
43
41
|
|
|
44
42
|
(function(){
|
|
45
|
-
console.log('expectRequire reset');
|
|
46
43
|
|
|
47
44
|
(function() {
|
|
48
|
-
console.log('require');
|
|
49
45
|
sut('./foo').return(fooFake);
|
|
50
46
|
sut.reset();
|
|
51
47
|
var returned = require('./foo');
|
package/index.d.ts
CHANGED
|
@@ -1,109 +1,138 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
T
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
extends
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
type AnyFunction = (...args: any[]) => any;
|
|
4
|
+
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : [];
|
|
5
|
+
type OverloadedParameters<T> = T extends {
|
|
6
|
+
(...args: infer A): any;
|
|
7
|
+
(...args: infer B): any;
|
|
8
|
+
}
|
|
9
|
+
? A | B
|
|
10
|
+
: T extends (...args: infer A) => any
|
|
11
|
+
? A
|
|
12
|
+
: never;
|
|
13
|
+
type OverloadedReturnType<T> = T extends {
|
|
14
|
+
(...args: any[]): infer A;
|
|
15
|
+
(...args: any[]): infer B;
|
|
16
|
+
}
|
|
17
|
+
? A | B
|
|
18
|
+
: T extends (...args: any[]) => infer A
|
|
19
|
+
? A
|
|
20
|
+
: never;
|
|
21
|
+
type OptionalTuple<T extends any[]> = { [K in keyof T]?: T[K] };
|
|
22
|
+
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
23
|
+
type CallbackFor<TArgs> = TArgs extends any[] ? (...args: TArgs) => void : never;
|
|
24
|
+
type FunctionProps<T> = T extends (...args: any[]) => any
|
|
25
|
+
? { [K in Exclude<keyof T, keyof Function>]: Mocked<T[K]> }
|
|
26
|
+
: {};
|
|
27
|
+
type MockedFunction<T extends AnyFunction> = MockFunction<
|
|
28
|
+
OverloadedParameters<T>,
|
|
29
|
+
T extends AxiosInstance
|
|
30
|
+
? Promise<AxiosResponse<any, any, {}>>
|
|
31
|
+
: OverloadedReturnType<T>
|
|
32
|
+
> &
|
|
33
|
+
T &
|
|
34
|
+
FunctionProps<T>;
|
|
35
|
+
|
|
36
|
+
interface RepeatControl {
|
|
37
|
+
repeat(times: number): RepeatControl;
|
|
38
|
+
repeatAny(): RepeatControl;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ExpectationTerminal<R, TArgs extends any[], TOrigArgs extends any[] = TArgs> {
|
|
42
|
+
return(value: R): RepeatControl;
|
|
43
|
+
returnAny(value?: any): RepeatControl;
|
|
44
|
+
whenCalled(callback: CallbackFor<TOrigArgs>): ExpectationTerminal<R, TArgs, TOrigArgs>;
|
|
45
|
+
repeat(times: number): RepeatControl;
|
|
46
|
+
repeatAny(): RepeatControl;
|
|
47
|
+
throw(error: any): ExpectationTerminal<R, TArgs, TOrigArgs>;
|
|
48
|
+
resolve(value: UnwrapPromise<R>): RepeatControl;
|
|
49
|
+
resolveLoose(value?: any): RepeatControl;
|
|
50
|
+
reject(error: Error): RepeatControl;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ExpectationChain<TArgs extends any[], R, TOrigArgs extends any[] = TArgs>
|
|
54
|
+
extends ExpectationTerminal<R, TArgs, TOrigArgs> {
|
|
55
|
+
expect(arg?: TArgs[0]): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
|
|
56
|
+
/** @deprecated Use ignoreAll() instead. */
|
|
57
|
+
expectAnything(): ExpectationChain<any[], R, TOrigArgs>;
|
|
58
|
+
ignoreAll(): ExpectationChain<any[], R, TOrigArgs>;
|
|
59
|
+
expectLoose(...args: any[]): ExpectationChain<any[], any, TOrigArgs>;
|
|
60
|
+
ignore(): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
|
|
61
|
+
/** @deprecated Use expect() instead. */
|
|
33
62
|
expectArray(
|
|
34
|
-
value
|
|
35
|
-
): ExpectationChain<Tail<TArgs>, R>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface MockFunction<TArgs extends any[], R> {
|
|
39
|
-
(...args: TArgs): R;
|
|
63
|
+
value?: TArgs[0] extends any[] ? TArgs[0] : any[]
|
|
64
|
+
): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface MockFunction<TArgs extends any[], R> {
|
|
68
|
+
(...args: TArgs): R;
|
|
40
69
|
// Allow any-args calls in addition to the original signature.
|
|
41
70
|
(...args: any[]): any;
|
|
42
|
-
expect():
|
|
43
|
-
|
|
44
|
-
expect(
|
|
45
|
-
expectAnything(): ExpectationChain<Tail<TArgs>, R>;
|
|
46
|
-
ignore(): ExpectationChain<Tail<TArgs>, R>;
|
|
71
|
+
expect(...args: OptionalTuple<TArgs>): ExpectationChain<Tail<TArgs>, R, TArgs>;
|
|
72
|
+
ignore(): ExpectationChain<Tail<TArgs>, R, TArgs>;
|
|
73
|
+
/** @deprecated Use expect() instead. */
|
|
47
74
|
expectArray(
|
|
48
|
-
value
|
|
49
|
-
): ExpectationChain<Tail<TArgs>, R>;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
declare function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
declare
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
75
|
+
value?: TArgs[0] extends any[] ? TArgs[0] : any[]
|
|
76
|
+
): ExpectationChain<Tail<TArgs>, R, TArgs>;
|
|
77
|
+
/** @deprecated Use ignoreAll() instead. */
|
|
78
|
+
expectAnything(): ExpectationChain<any[], R, TArgs>;
|
|
79
|
+
ignoreAll(): ExpectationChain<any[], R, TArgs>;
|
|
80
|
+
// Explicit loose expectations.
|
|
81
|
+
expectLoose(...args: any[]): ExpectationChain<any[], any, TArgs>;
|
|
82
|
+
verify(): true;
|
|
83
|
+
reset(): void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type Mocked<T> = T extends AnyFunction
|
|
87
|
+
? MockedFunction<T>
|
|
88
|
+
: T extends object
|
|
89
|
+
? { [K in keyof T]: Mocked<T[K]> } & { verify: () => true }
|
|
90
|
+
: T;
|
|
91
|
+
|
|
92
|
+
interface RequireExpectation {
|
|
93
|
+
return(value: any): RequireExpectation;
|
|
94
|
+
repeat(times: number): RequireExpectation;
|
|
95
|
+
repeatAny(): RequireExpectation;
|
|
96
|
+
whenCalled(callback: (...args: any[]) => void): RequireExpectation;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface ThenableMock<T = any> {
|
|
100
|
+
(valueToResolveWith?: T | null, errorToFailWith?: any): ThenableMock<T>;
|
|
101
|
+
then<U = T>(
|
|
102
|
+
success?: (value: T) => U | ThenableMock<U> | PromiseLike<U>,
|
|
103
|
+
fail?: (error: any) => U | ThenableMock<U> | PromiseLike<U>
|
|
104
|
+
): ThenableMock<U>;
|
|
105
|
+
resolve(value?: T): ThenableMock<T>;
|
|
106
|
+
reject(error: any): ThenableMock<never>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare function mock<T = any[], R = any>(): T extends any[]
|
|
110
|
+
? MockFunction<T, R>
|
|
111
|
+
: Mocked<T>;
|
|
112
|
+
declare function mock<T extends AnyFunction>(
|
|
113
|
+
original: T
|
|
114
|
+
): MockedFunction<T>;
|
|
115
|
+
declare function mock<T extends object>(subject: T): Mocked<T>;
|
|
116
|
+
|
|
117
|
+
declare function expectRequire(moduleName: string): RequireExpectation;
|
|
118
|
+
declare namespace expectRequire {
|
|
119
|
+
function reset(): void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare function requireMock<TArgs extends any[] = any[], R = any>(
|
|
123
|
+
moduleName: string
|
|
124
|
+
): MockFunction<TArgs, R>;
|
|
125
|
+
declare namespace requireMock {
|
|
126
|
+
function reset(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare function promise<T = any>(): ThenableMock<T>;
|
|
130
|
+
|
|
131
|
+
declare const aMock: {
|
|
132
|
+
mock: typeof mock;
|
|
133
|
+
expectRequire: typeof expectRequire;
|
|
134
|
+
requireMock: typeof requireMock;
|
|
135
|
+
promise: typeof promise;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export = aMock;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
4
|
|
|
5
5
|
(function(){
|
|
6
|
-
console.log('mockContext');
|
|
7
6
|
var newVerify = newRequireMock('../newMutableAnd');
|
|
8
7
|
var sut = require('../mockContext');
|
|
9
8
|
|
|
10
9
|
(function() {
|
|
11
|
-
console.log('empty input.new');
|
|
12
10
|
var verify = {};
|
|
13
11
|
newVerify.expect().return(verify);
|
|
14
12
|
var returned = sut();
|
|
@@ -19,7 +17,6 @@ var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
|
19
17
|
})();
|
|
20
18
|
|
|
21
19
|
(function() {
|
|
22
|
-
console.log('nonEmpty input.new');
|
|
23
20
|
var input = {};
|
|
24
21
|
var returned = sut(input);
|
|
25
22
|
|
|
@@ -27,4 +24,4 @@ var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
|
27
24
|
assert.equal(returned,input);
|
|
28
25
|
});
|
|
29
26
|
})();
|
|
30
|
-
})();
|
|
27
|
+
})();
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
var propertyMock = require('./propertyMock');
|
|
2
|
-
|
|
3
|
-
function collectPropertyNames(subject) {
|
|
4
|
-
var names = {};
|
|
5
|
-
for (var name in subject) {
|
|
6
|
-
names[name] = true;
|
|
7
|
-
}
|
|
8
|
-
var proto = Object.getPrototypeOf(subject);
|
|
9
|
-
while (proto && proto !== Object.prototype && proto !== Function.prototype) {
|
|
10
|
-
var props = Object.getOwnPropertyNames(proto);
|
|
11
|
-
for (var i = 0; i < props.length; i++) {
|
|
12
|
-
var prop = props[i];
|
|
13
|
-
if (prop === 'constructor' || names[prop])
|
|
14
|
-
continue;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
16
|
-
if (desc && typeof desc.value === 'function')
|
|
17
|
-
names[prop] = true;
|
|
18
|
-
}
|
|
19
|
-
proto = Object.getPrototypeOf(proto);
|
|
20
|
-
}
|
|
21
|
-
return Object.keys(names);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function execute(subject,mockObject) {
|
|
25
|
-
if (!(subject instanceof Object))
|
|
26
|
-
return;
|
|
27
|
-
var mockFuncProperties = require('./mockFuncProperties');
|
|
28
|
-
var propertyNames = collectPropertyNames(subject);
|
|
29
|
-
for(var i = 0; i < propertyNames.length; i++) {
|
|
30
|
-
var propertyName = propertyNames[i];
|
|
31
|
-
var property = subject[propertyName];
|
|
32
|
-
var mockProperty = mockObject[propertyName];
|
|
33
|
-
if (property instanceof Function)
|
|
34
|
-
subject[propertyName] = propertyMock(subject,propertyName,mockProperty);
|
|
35
|
-
mockFuncProperties(property,mockProperty);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
var propertyMock = require('./propertyMock');
|
|
2
|
+
|
|
3
|
+
function collectPropertyNames(subject) {
|
|
4
|
+
var names = {};
|
|
5
|
+
for (var name in subject) {
|
|
6
|
+
names[name] = true;
|
|
7
|
+
}
|
|
8
|
+
var proto = Object.getPrototypeOf(subject);
|
|
9
|
+
while (proto && proto !== Object.prototype && proto !== Function.prototype) {
|
|
10
|
+
var props = Object.getOwnPropertyNames(proto);
|
|
11
|
+
for (var i = 0; i < props.length; i++) {
|
|
12
|
+
var prop = props[i];
|
|
13
|
+
if (prop === 'constructor' || names[prop])
|
|
14
|
+
continue;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
16
|
+
if (desc && typeof desc.value === 'function')
|
|
17
|
+
names[prop] = true;
|
|
18
|
+
}
|
|
19
|
+
proto = Object.getPrototypeOf(proto);
|
|
20
|
+
}
|
|
21
|
+
return Object.keys(names);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function execute(subject,mockObject) {
|
|
25
|
+
if (!(subject instanceof Object))
|
|
26
|
+
return;
|
|
27
|
+
var mockFuncProperties = require('./mockFuncProperties');
|
|
28
|
+
var propertyNames = collectPropertyNames(subject);
|
|
29
|
+
for(var i = 0; i < propertyNames.length; i++) {
|
|
30
|
+
var propertyName = propertyNames[i];
|
|
31
|
+
var property = subject[propertyName];
|
|
32
|
+
var mockProperty = mockObject[propertyName];
|
|
33
|
+
if (property instanceof Function)
|
|
34
|
+
subject[propertyName] = propertyMock(subject,propertyName,mockProperty);
|
|
35
|
+
mockFuncProperties(property,mockProperty);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
module.exports = execute;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
|
-
var test = require('
|
|
2
|
+
var test = require('node:test');
|
|
3
3
|
var newRequireMock = require('../../partialMock/simple/newRequireMock');
|
|
4
4
|
var newMock = require('../../partialMock/simple/newMock');
|
|
5
5
|
|
|
6
6
|
(function(){
|
|
7
|
-
console.log('mockFuncProperties');
|
|
8
7
|
var newPropertyMock = newRequireMock('./propertyMock');
|
|
9
8
|
var mockFuncProperties = newRequireMock('./mockFuncProperties');
|
|
10
9
|
var sut = require('../mockFuncProperties');
|
|
11
10
|
|
|
12
11
|
(function() {
|
|
13
|
-
console.log('subject is non-primitive');
|
|
14
12
|
var subject = {};
|
|
15
13
|
var a2 = {};
|
|
16
14
|
var a = function() {};
|
|
@@ -54,7 +52,6 @@ var newMock = require('../../partialMock/simple/newMock');
|
|
|
54
52
|
})();
|
|
55
53
|
|
|
56
54
|
(function() {
|
|
57
|
-
console.log('subject is primitive');
|
|
58
55
|
var subject = 'a';
|
|
59
56
|
var mockObject = 'a';
|
|
60
57
|
|
|
@@ -64,4 +61,4 @@ var newMock = require('../../partialMock/simple/newMock');
|
|
|
64
61
|
assert(true);
|
|
65
62
|
});
|
|
66
63
|
})();
|
|
67
|
-
})();
|
|
64
|
+
})();
|