From d33cc44dfe38e3b75b2455e527ea2e0415e8b7e6 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sun, 23 Aug 2020 11:55:27 +0300 Subject: [PATCH] Add mention in docs for previous (#173) --- docs/05_content_nodes.md | 2 +- tests/doc/stringify.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/05_content_nodes.md b/docs/05_content_nodes.md index fbaafaa7..cc58e230 100644 --- a/docs/05_content_nodes.md +++ b/docs/05_content_nodes.md @@ -167,7 +167,7 @@ String(doc) #### `YAML.Document#createNode(value, options?): Node` -To create a new node, use the `createNode(value, options?)` document method. This will recursively wrap any input with appropriate `Node` containers. Generic objects as well as `Map` and its descendants become mappings, while arrays and other iterable objects result in sequences. +To create a new node, use the `createNode(value, options?)` document method. This will recursively wrap any input with appropriate `Node` containers. Generic JS `Object` values as well as `Map` and its descendants become mappings, while arrays and other iterable objects result in sequences. With `Object`, entries that have an `undefined` value are dropped. To specify the collection type, set `options.tag` to its identifying string, e.g. `"!!omap"`. Note that this requires the corresponding tag to be available in the document's schema. If `options.wrapScalars` is undefined or `true`, plain values are wrapped in `Scalar` objects. diff --git a/tests/doc/stringify.js b/tests/doc/stringify.js index 76338509..1a499753 100644 --- a/tests/doc/stringify.js +++ b/tests/doc/stringify.js @@ -727,7 +727,13 @@ describe('undefined values', () => { test("{ a: 'A', b: undefined, c: 'C' }", () => { expect(YAML.stringify({ a: 'A', b: undefined, c: 'C' })).toBe( - 'a: A\nc: C\n' + 'a: A\nc: C\n' // note: No `b` key + ) + }) + + test("{ a: 'A', b: null, c: 'C' }", () => { + expect(YAML.stringify({ a: 'A', b: null, c: 'C' })).toBe( + 'a: A\nb: null\nc: C\n' ) })