@tramvai/test-unit 2.7.0 → 2.11.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/README.md CHANGED
@@ -153,13 +153,13 @@ Most of the helpers accepts option `providers` which allows to redefine already
153
153
  For example, passing `providers` to helper `testAction` allows to access this provider inside action itself:
154
154
 
155
155
  ```tsx
156
- import { createAction } from '@tramvai/core';
156
+ import { declareAction } from '@tramvai/core';
157
157
  import { testAction } from '@tramvai/test-unit';
158
158
 
159
- const action = createAction({
159
+ const action = declareAction({
160
160
  name: 'action',
161
- fn: (_, __, { test }) => {
162
- console.log(test); // token value
161
+ fn() {
162
+ console.log(this.deps.test); // token value
163
163
  },
164
164
  deps: {
165
165
  test: 'token name',
package/lib/index.es.js CHANGED
@@ -15,12 +15,7 @@ import { MetricsModule as MetricsModule$1 } from '@tramvai/module-metrics';
15
15
  import { SERVER_TOKEN as SERVER_TOKEN$1 } from '@tramvai/tokens-server';
16
16
  import { WEB_FASTIFY_APP_TOKEN } from '@tramvai/tokens-server-private';
17
17
 
18
- /**
19
- * Helper for testing actions
20
- * @param action action itself
21
- * @param params options for creation ConsumerContext or instance of context
22
- */
23
- const testAction = (action, { initialState, providers, di, store, stores, context = createMockContext({ initialState, di, providers, store, stores }), } = {}) => {
18
+ function testAction(action, { initialState, providers, di, store, stores, context = createMockContext({ initialState, di, providers, store, stores }), } = {}) {
24
19
  return {
25
20
  /**
26
21
  * @description
@@ -32,7 +27,7 @@ const testAction = (action, { initialState, providers, di, store, stores, contex
32
27
  return context.executeAction(action, payload);
33
28
  },
34
29
  };
35
- };
30
+ }
36
31
 
37
32
  /**
38
33
  * Helper for testing Reducer
package/lib/index.js CHANGED
@@ -24,12 +24,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
24
24
  var mapObj__default = /*#__PURE__*/_interopDefaultLegacy(mapObj);
25
25
  var values__default = /*#__PURE__*/_interopDefaultLegacy(values);
26
26
 
27
- /**
28
- * Helper for testing actions
29
- * @param action action itself
30
- * @param params options for creation ConsumerContext or instance of context
31
- */
32
- const testAction = (action, { initialState, providers, di, store, stores, context = testMocks.createMockContext({ initialState, di, providers, store, stores }), } = {}) => {
27
+ function testAction(action, { initialState, providers, di, store, stores, context = testMocks.createMockContext({ initialState, di, providers, store, stores }), } = {}) {
33
28
  return {
34
29
  /**
35
30
  * @description
@@ -41,7 +36,7 @@ const testAction = (action, { initialState, providers, di, store, stores, contex
41
36
  return context.executeAction(action, payload);
42
37
  },
43
38
  };
44
- };
39
+ }
45
40
 
46
41
  /**
47
42
  * Helper for testing Reducer
@@ -10,6 +10,6 @@ declare type Options = Parameters<typeof getDiWrapper>[0];
10
10
  export declare const testModule: (Module: ModuleType | ExtendedModule, { modules, providers, di }?: Options) => {
11
11
  module: any;
12
12
  di: import("@tinkoff/dippy").Container;
13
- runLine: (line: import("@tinkoff/dippy/lib/createToken/createToken").MultiTokenInterface<import("@tramvai/core").Command>) => Promise<any[]>;
13
+ runLine: (line: import("@tinkoff/dippy").MultiTokenInterface<import("@tramvai/core").Command>) => Promise<any[]>;
14
14
  };
15
15
  export {};
@@ -1,22 +1,18 @@
1
- import type { Action } from '@tramvai/core';
1
+ import type { Action, TramvaiAction } from '@tramvai/core';
2
2
  import type { CONTEXT_TOKEN } from '@tramvai/tokens-common';
3
3
  import { createMockContext } from '@tramvai/test-mocks';
4
4
  declare type OptionsContext = Parameters<typeof createMockContext>[0];
5
5
  declare type Options = OptionsContext & {
6
6
  context?: typeof CONTEXT_TOKEN;
7
7
  };
8
+ interface Runner<Params extends any[], Result> {
9
+ run: (...params: Params) => Result;
10
+ }
8
11
  /**
9
12
  * Helper for testing actions
10
13
  * @param action action itself
11
14
  * @param params options for creation ConsumerContext or instance of context
12
15
  */
13
- export declare const testAction: <P>(action: Action<P, any, any>, { initialState, providers, di, store, stores, context, }?: Options) => {
14
- /**
15
- * @description
16
- * Run action
17
- * @param payload
18
- * @returns
19
- */
20
- run: (payload?: P | undefined) => Promise<any>;
21
- };
16
+ export declare function testAction<Params extends any[], Result, Deps>(action: TramvaiAction<Params, Result, Deps>, options?: Options): Runner<Params, Result>;
17
+ export declare function testAction<Payload, Result, Deps>(action: Action<Payload, Result, Deps>, options?: Options): Runner<[Payload], Result>;
22
18
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/test-unit",
3
- "version": "2.7.0",
3
+ "version": "2.11.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -18,21 +18,21 @@
18
18
  "build-for-publish": "true"
19
19
  },
20
20
  "dependencies": {
21
- "@tramvai/cli": "2.7.0",
22
- "@tramvai/core": "2.7.0",
23
- "@tramvai/module-common": "2.7.0",
24
- "@tramvai/module-log": "2.7.0",
25
- "@tramvai/module-metrics": "2.7.0",
26
- "@tramvai/module-mocker": "2.7.0",
27
- "@tramvai/module-render": "2.7.0",
28
- "@tramvai/module-router": "2.7.0",
29
- "@tramvai/module-server": "2.7.0",
30
- "@tramvai/state": "2.7.0",
31
- "@tramvai/test-helpers": "2.7.0",
32
- "@tramvai/test-mocks": "2.7.0",
33
- "@tramvai/tokens-common": "2.7.0",
34
- "@tramvai/tokens-server": "2.7.0",
35
- "@tramvai/tokens-server-private": "2.7.0",
21
+ "@tramvai/cli": "2.11.0",
22
+ "@tramvai/core": "2.11.0",
23
+ "@tramvai/module-common": "2.11.0",
24
+ "@tramvai/module-log": "2.11.0",
25
+ "@tramvai/module-metrics": "2.11.0",
26
+ "@tramvai/module-mocker": "2.11.0",
27
+ "@tramvai/module-render": "2.11.0",
28
+ "@tramvai/module-router": "2.11.0",
29
+ "@tramvai/module-server": "2.11.0",
30
+ "@tramvai/state": "2.11.0",
31
+ "@tramvai/test-helpers": "2.11.0",
32
+ "@tramvai/test-mocks": "2.11.0",
33
+ "@tramvai/tokens-common": "2.11.0",
34
+ "@tramvai/tokens-server": "2.11.0",
35
+ "@tramvai/tokens-server-private": "2.11.0",
36
36
  "utility-types": "^3.10.0"
37
37
  },
38
38
  "peerDependencies": {