示例工程 15-type-testing-api-design
15-type-testing-api-design/02-utility-type-tests/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { applyPatch, run } from './dist/main.js';
test('工具类型只在类型层,patch 的运行时行为是浅合并', () => {
const out = [];
const ret = run((msg) => out.push(msg));
assert.deepEqual(ret, ['1:Ada:ada@example.com']);
assert.deepEqual(out, ret);
const user = applyPatch({ id: 1, name: 'A' }, { name: 'B' });
assert.deepEqual(user, { id: 1, name: 'B' });
});