From ba0c015705bdd3691178ef461c607684e953a239 Mon Sep 17 00:00:00 2001 From: Ali Bosworth Date: Fri, 2 Oct 2020 11:33:33 -0400 Subject: [PATCH] Add coverage for the simple situation of two paragraphs Both with and without `preserveNewlines: true`. This currently fails when `preserveNewlines:true`, which seems weird, because the option should only result in more newlines, not fewer. Seems to have been introduced between 2.0.0 and 2.2.1, likely https://github.com/Rosey/markdown-draft-js/pull/112 --- test/draft-to-markdown.spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/draft-to-markdown.spec.js b/test/draft-to-markdown.spec.js index c9751b0..9ee621b 100644 --- a/test/draft-to-markdown.spec.js +++ b/test/draft-to-markdown.spec.js @@ -96,6 +96,30 @@ describe('draftToMarkdown', function () { markdown = draftToMarkdown(rawObject, {preserveNewlines: true}); expect(markdown).toEqual('> one\n> \n> blockquote\nHello :)'); }); + + it('creates distinct paragraphs when preserveNewlines is default (false)', function () { + /* eslint-disable */ + const rawObject = {"blocks":[ + {"key":"6iuat","text":"paragraph one","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}, + {"key":"603i9","text":"paragraph two","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}, + ],"entityMap":{}} + /* eslint-enable */ + + var markdown = draftToMarkdown(rawObject); + expect(markdown).toEqual('paragraph one\n\nparagraph two'); + }); + + it('creates distinct paragraphs when preserveNewlines is set to true', function () { + /* eslint-disable */ + const rawObject = {"blocks":[ + {"key":"6iuat","text":"paragraph one","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}, + {"key":"603i9","text":"paragraph two","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}, + ],"entityMap":{}} + /* eslint-enable */ + + var markdown = draftToMarkdown(rawObject, {preserveNewlines: true}); + expect(markdown).toEqual('paragraph one\n\nparagraph two'); + }); }); describe('entity conversion', function () {