@@ -39,7 +39,7 @@ exports['toUpperCase 1'] = '"FOOBAR"'
3939在异步并发测试中使用快照时,由于 JavaScript 的限制,你需要使用 [ 测试环境] ( /guide/test-context ) 中的 ` expect ` 来确保检测到正确的测试。
4040:::
4141
42- 如同前文 ,你可以使用 [ ` toMatchInlineSnapshot() ` ] ( /api/#tomatchinlinesnapshot ) 将内联快照存储在测试文件中。
42+ 同样 ,你可以使用 [ ` toMatchInlineSnapshot() ` ] ( /api/#tomatchinlinesnapshot ) 将内联快照存储在测试文件中。
4343
4444``` ts
4545import { expect , it } from ' vitest'
@@ -81,7 +81,7 @@ vitest -u
8181
8282## 文件快照 {#file-snapshots}
8383
84- 调用 ` toMatchSnapshot() ` 时,我们将所有快照存储在格式化的快照文件中。这意味着我们需要转义快照字符串中的一些字符(即双引号 ` " ` 和反引号 `\ ` `)。同时,你可能会丢失快照内容的语法突出显示(如果它们是某种语言)。
84+ 调用 ` toMatchSnapshot() ` 时,我们将所有快照存储在格式化的快照文件中。这意味着我们需要转义快照字符串中的一些字符(即双引号 ` " ` 和反引号 `` ` `` )。同时,你可能会丢失快照内容的语法突出显示(如果它们是某种语言)。
8585
8686为了改善这种情况,我们引入 [ ` toMatchFileSnapshot() ` ] ( /api/expect#tomatchfilesnapshot ) 以在文件中显式快照。这允许你为快照文件分配任何文件扩展名,并使它们更具可读性。
8787
@@ -114,23 +114,28 @@ test('button looks correct', async () => {
114114
115115## 自定义序列化程序 {#custom-serializer}
116116
117- 你可以添加自己的逻辑来修改快照的序列化方式。像 Jest 一样,Vitest 为内置的 JavaScript 类型、HTML 元素、ImmutableJS 和 React 元素提供了默认的序列化程序。
117+ 你可以添加自己的逻辑来修改快照的序列化方式。像 Jest 一样,Vitest 默认有内置的 JavaScript 类型、HTML 元素、ImmutableJS 和 React 元素提供了默认的序列化程序。
118118
119119可以使用 [ ` expect.addSnapshotSerializer ` ] ( /api/expect#expect-addsnapshotserializer ) 添加自定义序列器。
120120
121121``` ts
122122expect .addSnapshotSerializer ({
123123 serialize(val , config , indentation , depth , refs , printer ) {
124- // `printer` is a function that serializes a value using existing plugins.
125- return ` Pretty foo: ${printer (val .foo , config , indentation , depth , refs )} `
124+ // `printer` 是一个通过现有插件对值进行序列化的函数。
125+ return ` Pretty foo: ${printer (
126+ val .foo ,
127+ config ,
128+ indentation ,
129+ depth ,
130+ refs
131+ )} `
126132 },
127133 test(val ) {
128134 return val && Object .prototype .hasOwnProperty .call (val , ' foo' )
129135 },
130136})
131137```
132-
133- 我们还支持 [ snapshotSerializers] ( /config/#snapshotserializers ) 选项来隐式添加自定义序列化器。
138+ 我们还支持 [ snapshotSerializers] ( /config/#snapshotserializers ) 选项,可以隐式添加自定义序列化器。
134139
135140``` ts [path/to/custom-serializer.ts]
136141import { SnapshotSerializer } from ' vitest'
@@ -156,7 +161,7 @@ export default defineConfig({
156161})
157162```
158163
159- 如下所示的测试添加后 :
164+ 添加类似的测试后 :
160165
161166``` ts
162167test (' foo snapshot test' , () => {
0 commit comments