From 93ee98ea4b00045b3da0855e56f0370d6d41ed46 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 22 Mar 2020 20:32:39 +0000 Subject: [PATCH] tests: remove white space from getSelection(). This HACK fixes Firefox tests This is a bit of a hack, because it appears that getSelection() behaviour is not consistent across browsers. --- tests/frontend/specs/helper.js | 50 ++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/frontend/specs/helper.js b/tests/frontend/specs/helper.js index 302c19980..fa7ed4dda 100644 --- a/tests/frontend/specs/helper.js +++ b/tests/frontend/specs/helper.js @@ -136,7 +136,15 @@ describe("the test helper", function(){ helper.selectLines($startLine, $endLine, startOffset, endOffset); var selection = inner$.document.getSelection(); - expect(cleanText(selection.toString())).to.be("ort lines to t"); + + /* + * replace() is required here because Firefox keeps the line breaks. + * + * I'm not sure this is ideal behavior of getSelection() where the text + * is not consistent between browsers but that's the situation so that's + * how I'm covering it in this test. + */ + expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to t"); done(); }); @@ -154,7 +162,15 @@ describe("the test helper", function(){ helper.selectLines($startLine, $endLine, startOffset, endOffset); var selection = inner$.document.getSelection(); - expect(cleanText(selection.toString())).to.be("ort lines to test"); + + /* + * replace() is required here because Firefox keeps the line breaks. + * + * I'm not sure this is ideal behavior of getSelection() where the text + * is not consistent between browsers but that's the situation so that's + * how I'm covering it in this test. + */ + expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to test"); done(); }); @@ -172,7 +188,15 @@ describe("the test helper", function(){ helper.selectLines($startLine, $endLine, startOffset, endOffset); var selection = inner$.document.getSelection(); - expect(cleanText(selection.toString())).to.be("ort lines "); + + /* + * replace() is required here because Firefox keeps the line breaks. + * + * I'm not sure this is ideal behavior of getSelection() where the text + * is not consistent between browsers but that's the situation so that's + * how I'm covering it in this test. + */ + expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines "); done(); }); @@ -190,7 +214,15 @@ describe("the test helper", function(){ helper.selectLines($startLine, $endLine, startOffset, endOffset); var selection = inner$.document.getSelection(); - expect(cleanText(selection.toString())).to.be("ort lines to test"); + + /* + * replace() is required here because Firefox keeps the line breaks. + * + * I'm not sure this is ideal behavior of getSelection() where the text + * is not consistent between browsers but that's the situation so that's + * how I'm covering it in this test. + */ + expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to test"); done(); }); @@ -205,7 +237,15 @@ describe("the test helper", function(){ helper.selectLines($startLine, $endLine); var selection = inner$.document.getSelection(); - expect(cleanText(selection.toString())).to.be("short lines to test"); + + /* + * replace() is required here because Firefox keeps the line breaks. + * + * I'm not sure this is ideal behavior of getSelection() where the text + * is not consistent between browsers but that's the situation so that's + * how I'm covering it in this test. + */ + expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("short lines to test"); done(); });