diff --git a/__tests__/__snapshots__/index.test.tsx.snap b/__tests__/__snapshots__/index.test.tsx.snap
new file mode 100644
index 00000000..07a86f49
--- /dev/null
+++ b/__tests__/__snapshots__/index.test.tsx.snap
@@ -0,0 +1,57 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`HTMLReactParser parses HTML with newlines 1`] = `
+[
+ "
+",
+
,
+]
+`;
+
+exports[`HTMLReactParser parses HTML with newlines 2`] = `
+[
+
,
+ "
+",
+]
+`;
+
+exports[`HTMLReactParser parses HTML with newlines 3`] = `
+[
+ "
+",
+
,
+ "
+",
+]
+`;
+
+exports[`HTMLReactParser parses HTML with newlines 4`] = `
+
+ foo +bar +
+`; + +exports[`HTMLReactParser parses HTML with newlines 5`] = ` +[ ++ foo +
, + " +bar", +] +`; + +exports[`HTMLReactParser parses HTML with newlines 6`] = ` +[ + "foo", ++ + +bar +
, + " +", +] +`; diff --git a/__tests__/index.test.tsx b/__tests__/index.test.tsx index 695e26f2..55756f9a 100644 --- a/__tests__/index.test.tsx +++ b/__tests__/index.test.tsx @@ -39,13 +39,30 @@ describe('HTMLReactParser', () => { }, ); - it('parses "" to []', () => { + it('parses empty string to empty array', () => { expect(parse('')).toEqual([]); }); - it("returns string if it's not HTML", () => { - const string = 'text'; - expect(parse(string)).toBe(string); + it.each(['a', 'text'])('parses string', (text) => { + expect(parse(text)).toBe(text); + }); + + it.each(['\n', '\r', '\n\r', 'foo\nbar', 'foo\rbar', 'foo\n\rbar\r'])( + 'parses string with newlines %p', + (text) => { + expect(parse(text)).toBe(text); + }, + ); + + it.each([ + '\nfoo\nbar\r
', + 'foo
\rbar', + 'foo\n\rbar
\r', + ])('parses HTML with newlines', (html) => { + expect(parse(html)).toMatchSnapshot(); }); it('parses single HTML element', () => { diff --git a/package-lock.json b/package-lock.json index e52633dd..61e5ae9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "domhandler": "5.0.3", - "html-dom-parser": "5.0.10", + "html-dom-parser": "5.0.11", "react-property": "2.0.2", "style-to-js": "1.1.16" }, @@ -5521,10 +5521,9 @@ } }, "node_modules/html-dom-parser": { - "version": "5.0.10", - "resolved": "https://registry.npmjs.org/html-dom-parser/-/html-dom-parser-5.0.10.tgz", - "integrity": "sha512-GwArYL3V3V8yU/mLKoFF7HlLBv80BZ2Ey1BzfVNRpAci0cEKhFHI/Qh8o8oyt3qlAMLlK250wsxLdYX4viedvg==", - "license": "MIT", + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/html-dom-parser/-/html-dom-parser-5.0.11.tgz", + "integrity": "sha512-iORudm2K0c0DYeEj4AbrG9PFzgp1dpFGkJUAiBlVTkeyaNf2YYIs1b0dF7rQUPnDZimkLx+Jls+CvRIKO/++Tg==", "dependencies": { "domhandler": "5.0.3", "htmlparser2": "9.1.0" diff --git a/package.json b/package.json index 20163f98..5c107193 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ ], "dependencies": { "domhandler": "5.0.3", - "html-dom-parser": "5.0.10", + "html-dom-parser": "5.0.11", "react-property": "2.0.2", "style-to-js": "1.1.16" },