From 35b6e04108ade60adf4702031096ceec5bb2a540 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 04:25:20 +0000 Subject: [PATCH 1/2] build(deps): bump html-dom-parser from 5.0.10 to 5.0.11 Bumps [html-dom-parser](https://github.com/remarkablemark/html-dom-parser) from 5.0.10 to 5.0.11. - [Release notes](https://github.com/remarkablemark/html-dom-parser/releases) - [Changelog](https://github.com/remarkablemark/html-dom-parser/blob/master/CHANGELOG.md) - [Commits](https://github.com/remarkablemark/html-dom-parser/compare/v5.0.10...v5.0.11) --- updated-dependencies: - dependency-name: html-dom-parser dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 9 ++++----- package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) 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" }, From 598871ed18da5a9a99d83adddc64792571ca9126 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 3 Dec 2024 23:45:48 -0500 Subject: [PATCH 2/2] test(index): add snapshot tests for string and html with newlines --- __tests__/__snapshots__/index.test.tsx.snap | 57 +++++++++++++++++++++ __tests__/index.test.tsx | 25 +++++++-- 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 __tests__/__snapshots__/index.test.tsx.snap 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([ + '\n
', + '
\r', + '\n
\r', + '

foo\nbar\r

', + '

foo

\rbar', + 'foo

\n\rbar

\r', + ])('parses HTML with newlines', (html) => { + expect(parse(html)).toMatchSnapshot(); }); it('parses single HTML element', () => {