@mpcore/test 1.2.4 → 1.2.5-dev.20261112.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/README.md +2 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +3 -3
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -31,6 +31,8 @@ finally {
|
|
|
31
31
|
|
|
32
32
|
查询支持 text、role、test id、attribute、`within()` 及 `get/query/find/getAll/findAll` 变体,并保留 `$` / `$$` 选择器逃生口。`tap/input/change/blur/trigger` 会等待同步更新和 microtask 稳定后刷新逻辑树。保留的 `within()` 查询共享最新快照,并按原 runtime `nodeId` 确定范围;该 ID 缺失时查询报错,不会按相同 test id 重定位。runtime 可能在条件节点恢复等情况下复用同一路径的 `nodeId`,此时保留的节点和作用域会解析到当前快照中该 ID 对应的节点。
|
|
33
33
|
|
|
34
|
+
`mpcoreMatchers.toHaveTextContent(node, expected)` 保留部分字符串与正则匹配,数字按文本比较;省略 `expected` 检查文本非空。第三个参数 `{ normalizeWhitespace: true }` 显式合并连续空白并去除首尾空白,默认保持原文本。`@mpcore/vitest` 将这些 matcher 注册到 `expect`,类型可与 Vitest browser 的 DOM matcher 同时加载。
|
|
35
|
+
|
|
34
36
|
事件需要显式订阅:`events: ['change']` 从挂载阶段开始收集,`on: { change(detail, event) {} }` 同时收集并回调。挂载后可调用 `result.on('change', listener)`,返回取消订阅函数;省略 listener 时只收集。`off()` 取消对应订阅,已收集的 `emitted()` 历史保留。动态订阅复用组件实例。
|
|
35
37
|
|
|
36
38
|
子组件可按标签名递归替换:
|
package/dist/index.d.mts
CHANGED
|
@@ -145,9 +145,11 @@ export type MiniProgramNodeLike = MiniProgramNode;
|
|
|
145
145
|
export declare function createWxMock(definition?: WxHostMock): WxHostMock;
|
|
146
146
|
export declare function applyWxMock(session: HeadlessSession, definition?: WxHostMock): void;
|
|
147
147
|
export declare function toBeInTheMiniProgram(node: MiniProgramNode): MiniProgramMatcherResult;
|
|
148
|
-
export declare function toHaveTextContent(node: MiniProgramNode, expected
|
|
148
|
+
export declare function toHaveTextContent(node: MiniProgramNode, expected?: string | number | RegExp, options?: {
|
|
149
|
+
normalizeWhitespace: boolean;
|
|
150
|
+
}): MiniProgramMatcherResult;
|
|
149
151
|
export declare function toHaveEmitted(source: MiniProgramEmissionSource, eventName: string, expected?: unknown): MiniProgramMatcherResult;
|
|
150
|
-
export declare function toHaveAttribute(node: MiniProgramNode, name: string, expected?:
|
|
152
|
+
export declare function toHaveAttribute(node: MiniProgramNode, name: string, expected?: unknown): MiniProgramMatcherResult;
|
|
151
153
|
export declare function toHaveDataset(node: MiniProgramNode, expected: Record<string, unknown>): MiniProgramMatcherResult;
|
|
152
154
|
export declare const mpcoreMatchers: {
|
|
153
155
|
toBeInTheMiniProgram: typeof toBeInTheMiniProgram;
|
package/dist/index.mjs
CHANGED
|
@@ -23,12 +23,12 @@ function toBeInTheMiniProgram(node) {
|
|
|
23
23
|
pass
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
function toHaveTextContent(node, expected) {
|
|
27
|
-
const actual = node.textContent;
|
|
26
|
+
function toHaveTextContent(node, expected, options) {
|
|
27
|
+
const actual = options?.normalizeWhitespace ? node.textContent.replace(/\s+/gu, " ").trim() : node.textContent;
|
|
28
28
|
if (expected instanceof RegExp) expected.lastIndex = 0;
|
|
29
29
|
return {
|
|
30
30
|
message: () => `Expected mini-program node text ${JSON.stringify(actual)} to match ${String(expected)}.`,
|
|
31
|
-
pass:
|
|
31
|
+
pass: expected === void 0 ? actual.length > 0 : expected instanceof RegExp ? expected.test(actual) : actual.includes(String(expected))
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
function toHaveEmitted(source, eventName, expected) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/test",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.5-dev.20261112.3",
|
|
5
5
|
"description": "Testing Library-style utilities for compiled WeChat mini-program artifacts",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,11 +42,19 @@
|
|
|
42
42
|
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mpcore/simulator": "1.3.3"
|
|
45
|
+
"@mpcore/simulator": "1.3.4-dev.20261112.3"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|
|
49
|
-
"registry": "https://registry.npmjs.org"
|
|
49
|
+
"registry": "https://registry.npmjs.org/",
|
|
50
|
+
"tag": "snapshot-nightly"
|
|
51
|
+
},
|
|
52
|
+
"repoctlSnapshot": {
|
|
53
|
+
"kind": "nightly",
|
|
54
|
+
"commit": "8ca9aafdedcb688596814e1430c8e571fb540b93",
|
|
55
|
+
"buildId": "43314231283-1",
|
|
56
|
+
"identityKey": "af86ccdf5befcdc313380a806c430308b056b012d4541fee2c76ee1363600bd1",
|
|
57
|
+
"tag": "snapshot-nightly"
|
|
50
58
|
},
|
|
51
59
|
"scripts": {
|
|
52
60
|
"dev": "tsdown -w",
|
|
@@ -57,4 +65,4 @@
|
|
|
57
65
|
"test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
|
|
58
66
|
"typecheck": "tsc --noEmit"
|
|
59
67
|
}
|
|
60
|
-
}
|
|
68
|
+
}
|