From 3c7c5108ff30cb53d6bfe9cc8e87847f0a6ac4a5 Mon Sep 17 00:00:00 2001 From: VKD Date: Sun, 6 Sep 2020 15:17:54 +0530 Subject: [PATCH] fix: Testsuite runtime error message not converted to html --- src/Components/Modal/ErrorMessage.js | 4 +++- src/Components/Modal/ErrorMessage.test.js | 11 ++++++++++ .../__snapshots__/ErrorMessage.test.js.snap | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Components/Modal/ErrorMessage.js b/src/Components/Modal/ErrorMessage.js index 4d047c7..a96d1cf 100644 --- a/src/Components/Modal/ErrorMessage.js +++ b/src/Components/Modal/ErrorMessage.js @@ -19,12 +19,14 @@ export default class ErrorMessage extends React.Component { createMarkup(text) { let result = ''; - if (text && text.length > 0) { + if (Array.isArray(text) && text.length > 0) { for (let i = 0; i < text.length; i++) { result = result.concat( convert.toHtml(this.escapeHtml(text[i])), ); } + } else if (!Array.isArray(text) && text && text.length > 0) { + result = result.concat(convert.toHtml(this.escapeHtml(text))); } return { __html: result }; } diff --git a/src/Components/Modal/ErrorMessage.test.js b/src/Components/Modal/ErrorMessage.test.js index d8aa17a..9802cff 100644 --- a/src/Components/Modal/ErrorMessage.test.js +++ b/src/Components/Modal/ErrorMessage.test.js @@ -21,3 +21,14 @@ test('Should return html message', () => { ); expect(container).toMatchSnapshot(); }); + +test('Should return html message as string', () => { + const messages = '\x1b[30mblack\x1b[37mwhite'; + const { container } = render( + , + ); + expect(container.firstChild.firstChild.firstChild.textContent).toEqual( + 'blackwhite', + ); + expect(container).toMatchSnapshot(); +}); diff --git a/src/Components/Modal/__snapshots__/ErrorMessage.test.js.snap b/src/Components/Modal/__snapshots__/ErrorMessage.test.js.snap index f2294c5..1eb6598 100644 --- a/src/Components/Modal/__snapshots__/ErrorMessage.test.js.snap +++ b/src/Components/Modal/__snapshots__/ErrorMessage.test.js.snap @@ -20,3 +20,24 @@ exports[`Should return html message 1`] = ` `; + +exports[`Should return html message as string 1`] = ` +
+
+
+      
+        black
+        
+          white
+        
+      
+    
+
+
+`;