@vnejs/plugins.views.screens.loading 0.1.14 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.screens.loading",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "tsconfig.json"
19
19
  ],
20
20
  "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1",
21
+ "test": "npx @vnejs/monorepo test",
22
22
  "build": "npx @vnejs/monorepo package",
23
23
  "publish:major:plugin": "npm run publish:major",
24
24
  "publish:minor:plugin": "npm run publish:minor",
@@ -40,6 +40,14 @@
40
40
  "@vnejs/uis.react": "~0.1.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@vnejs/configs.ts-common": "~0.1.0"
43
+ "@vnejs/configs.ts-common": "~0.1.0",
44
+ "@vnejs/configs.vitest": "~0.1.0",
45
+ "@vnejs/test-utils": "~0.1.0",
46
+ "@vnejs/contracts.text.locs": "~0.1.0",
47
+ "@vnejs/contracts.views.screens.loading": "~0.1.0",
48
+ "@vnejs/module.core": "~0.1.0",
49
+ "@vnejs/module.components": "~0.1.0",
50
+ "@vnejs/shared": "~0.1.0",
51
+ "@vnejs/uis.react": "~0.1.0"
44
52
  }
45
53
  }
@@ -0,0 +1,30 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { Loading } from "../modules/loading.js";
6
+ import { createLoadingTestModule, registerLoadingPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
7
+
8
+ describe("Loading", () => {
9
+ beforeEach(() => {
10
+ registerLoadingPluginVne();
11
+ vi.useFakeTimers();
12
+ });
13
+
14
+ it("EMIT shows, runs promise, and hides", async () => {
15
+ const { observer } = createLoadingTestModule(Loading);
16
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
17
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
18
+ const promiseFunc = vi.fn(async () => undefined);
19
+
20
+ const emitPromise = observer.emit(SUBSCRIBE_EVENTS.EMIT, { promiseFunc });
21
+
22
+ expect(show).toHaveBeenCalledOnce();
23
+
24
+ await vi.runAllTimersAsync();
25
+ await emitPromise;
26
+
27
+ expect(promiseFunc).toHaveBeenCalledOnce();
28
+ expect(hide).toHaveBeenCalledOnce();
29
+ });
30
+ });
@@ -0,0 +1,33 @@
1
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.screens.loading";
2
+ import {
3
+ createTestModule as baseCreateTestModule,
4
+ registerCoreVne,
5
+ registerVnePlugin,
6
+ stubSilentEvent,
7
+ } from "@vnejs/test-utils";
8
+
9
+ export const registerLoadingPluginVne = () => {
10
+ registerCoreVne();
11
+ registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
12
+ };
13
+
14
+ export const createLoadingTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
15
+ ModuleClass: T,
16
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
17
+ ) => {
18
+ const result = baseCreateTestModule(ModuleClass, {
19
+ state: {
20
+ loading: { isShow: false },
21
+ ...(options.state ?? {}),
22
+ },
23
+ ...options,
24
+ });
25
+
26
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
27
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
28
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
29
+
30
+ return result;
31
+ };
32
+
33
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME };
package/tsconfig.json CHANGED
@@ -6,5 +6,5 @@
6
6
  "jsx": "react-jsx"
7
7
  },
8
8
  "include": ["src/**/*.ts", "src/**/*.tsx"],
9
- "exclude": ["dist", "node_modules"]
9
+ "exclude": ["dist", "node_modules", "src/tests"]
10
10
  }