@@ -191,9 +191,9 @@ export default {
191191 return ` Pretty foo: ${printer (val .foo , config , indentation , depth , refs )} `
192192 },
193193 test(val ) {
194- return val && Object .hasOwn (val , ' foo' )
194+ return val && Object .prototype . hasOwnProperty . call (val , ' foo' )
195195 },
196- } satisfies SnapshotSerializer
196+ } satisfies SnapshotSerializ : er
197197```
198198
199199``` ts [vitest.config.ts]
@@ -235,7 +235,7 @@ Pretty foo: Object {
235235可通过 ` vitest ` 提供的 ` Snapshots ` 组合式函数构建自定义快照匹配器。这些函数允许你在生成快照前对值进行转换,同时完整保留快照生命周期支持(创建、更新、内联重写)。
236236
237237``` ts
238- import { expect , Snapshots , test } from ' vitest'
238+ import { expect , test , Snapshots } from ' vitest'
239239
240240const { toMatchFileSnapshot, toMatchInlineSnapshot, toMatchSnapshot } = Snapshots
241241
@@ -519,7 +519,7 @@ test('user data inline', () => {
519519
520520Vitest 提供了与 [ Jest] ( https://jestjs.io/docs/snapshot-testing ) 几乎兼容的快照功能,除少数例外:
521521
522- ### 1. 快照文件中的注释标头不同 {#\ _ 1-comment-header-in-the-snapshot-file-is-different}
522+ ### 1. 快照文件中的注释标头不同 {#_ 1-comment-header-in-the-snapshot-file-is-different}
523523
524524``` diff
525525- // Jest Snapshot v1, https://goo.gl/fbAQLP
@@ -528,7 +528,7 @@ Vitest 提供了与 [Jest](https://jestjs.io/docs/snapshot-testing) 几乎兼容
528528
529529这实际上不会影响功能,但在从 Jest 迁移时可能会影响提交差异。
530530
531- ### 2. ` printBasicPrototype ` 默认为 ` false ` {#\ _ 2-printbasicprototype-is-default-to-false}
531+ ### 2. ` printBasicPrototype ` 默认为 ` false ` {#_ 2-printbasicprototype-is-default-to-false}
532532
533533Jest 和 Vitest的快照功能均基于 ` pretty-format ` 实现,但 Vitest 在 [ ` @vitest/pretty-format ` ] ( https://npmx.dev/package/@vitest/pretty-format ) 基础上应用了自定义的快照默认配置。具体而言,Vitest将 ` printBasicPrototype ` 设为 ` false ` 以生成更简洁的快照输出,而 Jest 29.0.0 以下版本默认将该值设为 ` true ` 。
534534
@@ -576,7 +576,7 @@ export default defineConfig({
576576})
577577```
578578
579- ### 3. 使用 V 形 ` > ` 而非冒号 ` : ` 作为自定义消息的分隔符 {#\ _ 3-chevron-is-used-as-a-separator-instead-of-colon-for-custom-messages}
579+ ### 3. 使用 V 形 ` > ` 而非冒号 ` : ` 作为自定义消息的分隔符 {#_ 3-chevron-is-used-as-a-separator-instead-of-colon-for-custom-messages}
580580
581581当创建快照文件期间传递自定义消息时,Vitest 使用 V 形 ` > ` 作为分隔符而不是冒号 ` : ` 以提高自定义消息可读性。
582582
@@ -602,7 +602,7 @@ exports[`toThrowErrorMatchingSnapshot: hint 1`] = `"error"`;
602602exports[`toThrowErrorMatchingSnapshot > hint 1`] = `[Error: error]`;
603603```
604604
605- ### 4. ` toThrowErrorMatchingSnapshot ` 和 ` toThrowErrorMatchingInlineSnapshot ` 的默认 ` Error ` 快照不同 {#\ _ 4-default-error-snapshot-is-different-for-tothrowerrormatchingsnapshot-and-tothrowerrormatchinginlinesnapshot}
605+ ### 4. ` toThrowErrorMatchingSnapshot ` 和 ` toThrowErrorMatchingInlineSnapshot ` 的默认 ` Error ` 快照不同 {#_ 4-default-error-snapshot-is-different-for-tothrowerrormatchingsnapshot-and-tothrowerrormatchinginlinesnapshot}
606606
607607``` js
608608import { expect , test } from ' vitest'
0 commit comments