a_mock 2.0.4 → 2.0.5

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 (3) hide show
  1. package/README.md +15 -13
  2. package/index.d.ts +17 -21
  3. package/package.json +18 -7
package/README.md CHANGED
@@ -94,24 +94,26 @@ mock(['a','b']); //throws unexpected arguments
94
94
  mock(['foo', 'bar']); //throws unexpected arguments
95
95
  ```
96
96
 
97
- __Expecting struct__
98
-
99
- ```js
100
- var mock = require('a_mock').mock();
101
- var obj = {};
97
+ __Expecting struct__
98
+
99
+ ```js
100
+ var mock = require('a_mock').mock();
101
+ var obj = {};
102
102
  mock.expect({a : 1}).return('fake1');
103
103
  mock.expect({a : 2}).return('fake2');
104
104
  mock.expect({a : 2, b : {c : 'foo', d : ['me', 'too']}}).return('fake3');
105
105
  mock.expect(obj).return('fake4');
106
106
  mock.expect({}).return('will never happen');
107
107
 
108
- mock({a : 'x'}); //throws unexpected arguments
109
- mock({a : 1}); //returns 'fake1'
110
- mock({a : 2}); //returns 'fake2'
111
- mock({a : 2, b : {c : 'foo', d : ['me', 'too']}}); //returns 'fake3'
112
- mock(obj); //returns 'fake4'
113
- mock({}); //throws unexpected arguments
114
- ```
108
+ mock({a : 'x'}); //throws unexpected arguments
109
+ mock({a : 1}); //returns 'fake1'
110
+ mock({a : 2}); //returns 'fake2'
111
+ mock({a : 2, b : {c : 'foo', d : ['me', 'too']}}); //returns 'fake3'
112
+ mock(obj); //returns 'fake4'
113
+ mock({}); //throws unexpected arguments cause leaf properties are not equal
114
+ ```
115
+
116
+ Note: Struct matching is strict on leaf properties. All leaf property values must be equal to match, and an empty object does not match a non-empty expected struct.
115
117
 
116
118
  __Repeats__
117
119
 
@@ -447,4 +449,4 @@ function success(arg) {
447
449
  function error(e) {
448
450
  console.log(e.stack);//will happen
449
451
  }
450
- ```
452
+ ```
package/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { AxiosInstance, AxiosResponse } from 'axios';
2
-
3
1
  type AnyFunction = (...args: any[]) => any;
4
2
  type Tail<T extends any[]> = T extends [any, ...infer R] ? R : [];
5
3
  type OverloadedParameters<T> = T extends {
@@ -26,9 +24,7 @@ type FunctionProps<T> = T extends (...args: any[]) => any
26
24
  : {};
27
25
  type MockedFunction<T extends AnyFunction> = MockFunction<
28
26
  OverloadedParameters<T>,
29
- T extends AxiosInstance
30
- ? Promise<AxiosResponse<any, any, {}>>
31
- : OverloadedReturnType<T>
27
+ OverloadedReturnType<T>
32
28
  > &
33
29
  T &
34
30
  FunctionProps<T>;
@@ -40,7 +36,7 @@ interface RepeatControl {
40
36
 
41
37
  interface ExpectationTerminal<R, TArgs extends any[], TOrigArgs extends any[] = TArgs> {
42
38
  return(value: R): RepeatControl;
43
- returnLoose(value?: any): RepeatControl;
39
+ returnLoose(value?: any): RepeatControl;
44
40
  whenCalled(callback: CallbackFor<TOrigArgs>): ExpectationTerminal<R, TArgs, TOrigArgs>;
45
41
  repeat(times: number): RepeatControl;
46
42
  repeatAny(): RepeatControl;
@@ -55,25 +51,25 @@ interface ExpectationChain<TArgs extends any[], R, TOrigArgs extends any[] = TAr
55
51
  expect(arg?: TArgs[0]): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
56
52
  /** @deprecated Use ignoreAll() instead. */
57
53
  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. */
62
- expectArray(
63
- value?: TArgs[0] extends any[] ? TArgs[0] : any[]
64
- ): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
54
+ ignoreAll(): ExpectationChain<any[], R, TOrigArgs>;
55
+ expectLoose(...args: any[]): ExpectationChain<any[], any, TOrigArgs>;
56
+ ignore(): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
57
+ /** @deprecated Use expect() instead. */
58
+ expectArray(
59
+ value?: TArgs[0] extends any[] ? TArgs[0] : any[]
60
+ ): ExpectationChain<Tail<TArgs>, R, TOrigArgs>;
65
61
  }
66
62
 
67
63
  interface MockFunction<TArgs extends any[], R> {
68
64
  (...args: TArgs): R;
69
- // Allow any-args calls in addition to the original signature.
70
- (...args: any[]): any;
71
- expect(...args: OptionalTuple<TArgs>): ExpectationChain<Tail<TArgs>, R, TArgs>;
72
- ignore(): ExpectationChain<Tail<TArgs>, R, TArgs>;
73
- /** @deprecated Use expect() instead. */
74
- expectArray(
75
- value?: TArgs[0] extends any[] ? TArgs[0] : any[]
76
- ): ExpectationChain<Tail<TArgs>, R, TArgs>;
65
+ // Allow any-args calls in addition to the original signature.
66
+ (...args: any[]): any;
67
+ expect(...args: OptionalTuple<TArgs>): ExpectationChain<Tail<TArgs>, R, TArgs>;
68
+ ignore(): ExpectationChain<Tail<TArgs>, R, TArgs>;
69
+ /** @deprecated Use expect() instead. */
70
+ expectArray(
71
+ value?: TArgs[0] extends any[] ? TArgs[0] : any[]
72
+ ): ExpectationChain<Tail<TArgs>, R, TArgs>;
77
73
  /** @deprecated Use ignoreAll() instead. */
78
74
  expectAnything(): ExpectationChain<any[], R, TArgs>;
79
75
  ignoreAll(): ExpectationChain<any[], R, TArgs>;
package/package.json CHANGED
@@ -1,18 +1,29 @@
1
1
  {
2
2
  "name": "a_mock",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "title": "a_mock",
7
7
  "description": "Sub package of a. Mocking framework",
8
- "keywords": ["mock","mocking","partial mock","strict mock","tdd","stub","stubbing","mock require","verify"],
8
+ "keywords": [
9
+ "mock",
10
+ "mocking",
11
+ "partial mock",
12
+ "strict mock",
13
+ "tdd",
14
+ "stub",
15
+ "stubbing",
16
+ "mock require",
17
+ "verify"
18
+ ],
9
19
  "scripts": {
10
20
  "test": "node --test **/*Spec/test*.js"
11
-
12
21
  },
13
- "dependencies": { },
14
- "repository" : {
15
- "type" : "git",
16
- "url" : "git@github.com:alfateam/a_mock.git"
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git@github.com:alfateam/a_mock.git"
25
+ },
26
+ "devDependencies": {
27
+ "axios": "^1.13.2"
17
28
  }
18
29
  }