diff options
author | Moshe Atlow <moshe@atlow.co.il> | 2022-08-11 16:07:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 16:07:52 +0300 |
commit | 8f9d1ab5ec3d3fd2ee4c95f1699c3c10b08108b4 (patch) | |
tree | ca093baa4ea45d62c1ce91707c4eb2ede41e83c4 /doc/api/assert.md | |
parent | 818bd6cb4df290cb2d46e75c7286d4ae03b4ea2b (diff) |
assert: add assert.Snapshot
PR-URL: https://github.com/nodejs/node/pull/44095
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'doc/api/assert.md')
-rw-r--r-- | doc/api/assert.md | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md index 4958e6dd7df..34c0e47ecf0 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -2006,6 +2006,32 @@ argument, then `error` is assumed to be omitted and the string will be used for example in [`assert.throws()`][] carefully if using a string as the second argument gets considered. +## `assert.snapshot(value, name)` + +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `value` {any} the value to snapshot +* `name` {string} the name of snapshot. +* Returns: {Promise} + +reads a 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()` will return a rejected `Promise` +with an [`AssertionError`][]. + +If the snapshot file does not exist, the snapshot is written. + +In case it is needed to force a snapshot update, +use [`--update-assert-snapshot`][]; + +By default, a snapshot is read and written to a file, +using the same name as the main entrypoint with `.snapshot` as the extension. + ## `assert.strictEqual(actual, expected[, message])` <!-- YAML @@ -2442,6 +2468,7 @@ argument. [Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript [Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring [`!=` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality +[`--update-assert-snapshot`]: cli.md#--update-assert-snapshot [`===` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality [`==` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality [`AssertionError`]: #class-assertassertionerror @@ -2473,5 +2500,6 @@ argument. [`process.on('exit')`]: process.md#event-exit [`tracker.calls()`]: #trackercallsfn-exact [`tracker.verify()`]: #trackerverify +[`util.inspect()`]: util.md#utilinspectobject-options [enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties [prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots |