快照测试(Snapshot testing) 会捕获某些输出的“快照”(通常是 UI 组件的渲染结果或某个数据结构),并将后续运行的结果与之进行比较——当输出发生变化时发出提示。它对于检测意外更改很有用,但也有一些需要理解的局限性。
快照测试的工作原理
1. First run → the test RECORDS the output (e.g. a rendered component) as a SNAPSHOT file
2. Later runs → COMPARE the current output to the saved snapshot:
→ MATCHES → pass; DIFFERS → fail (the output changed)
3. If the change is INTENTIONAL → UPDATE the snapshot (review the diff, then accept)
(, {
tree = ().();
(tree).();
});
