assert.snapshot(value, name)


    从文件中读取 name 快照并将 value 与快照进行比较。 valueutil.inspect() 序列化。 如果该值不严格等于快照,则 assert.snapshot() 返回一个使用 AssertionError 拒绝的 Promise

    Stability: 1 - Experimental

    Reads the name snapshot from a file and compares value to the snapshot. value is serialized with util.inspect(). If the value is not strictly equal to the snapshot, assert.snapshot() returns a rejected Promise with an AssertionError.

    The snapshot filename uses the same basename as the application's main entrypoint with a .snapshot extension. If the snapshot file does not exist, it is created. The --update-assert-snapshot command line flag can be used to force the update of an existing snapshot.

    import assert from 'node:assert/strict';
    
    // Assuming that the application's main entrypoint is app.mjs, this reads the
    // 'snapshotName' snapshot from app.snapshot and strictly compares its value
    // to `util.inspect('value')`.
    await assert.snapshot('value', 'snapshotName');const assert = require('node:assert/strict');
    
    (async () => {
      // Assuming that the application's main entrypoint is app.js, this reads the
      // 'snapshotName' snapshot from app.snapshot and strictly compares its value
      // to `util.inspect('value')`.
      await assert.snapshot('value', 'snapshotName');
    })();