Issue while comparing a string value(prepared using concatenated strings) and an another string value(prepared using buffer)
See original GitHub issueI would like to raise an issue that I am facing since last few months. While working on Node.js I have defined many test cases as below code snippet. While most of them works and getting passed with proper data, it will fail for some of the cases even though there is no change of even single space in two string values to getting compared.
This issue will not come in all the systems. For example in some desktop systems it fails while in deployed servers, this same piece of code and data will never fail. Here there is no change I see even in terms of single character(alphabet, special char, blank space or anything, these is true with many such cases where it fails). That is strange !
See attached screenshot
I tried searching solutions through many sources online but no success .
If you find this as an issue, could you please resolve it ?
Code:
const chai = require('chai');
const expect = chai.expect;
const fs = require('fs');
const jsFile = require('../../../lib/<some-file-path>');
describe('test case', function () {
it('test scenario', function (done) {
jsFile.someOperation(someValue, function (htmlText) {
// htmlText here is string value like say, let htmlText = "<a>" + "Link Label" + "</a>";
fs.readFile('<File_Path>/resultTestFileName.html', "UTF-8", function (err, buf) {
let compareToHtml = buf.toString();
expect(compareToHtml).to.equal(htmlText);
done();
});
})
});
});
Chai and Mocha version used: “chai”: “^3.5.0”, “chai-http”: “^2.0.1”, “mocha”: “^2.4.5”,
Feel free to ask if you need more details.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
The eol package has worked in a specific way. Sharing the solution here.
One may need to write a case something like this to make it work.
Here I have used eol.lf function as below to update the resultTestFileName.html file in a Windows based system .Then this case with pass without any issue in Unix and Windows both.
Kinda depends on your application’s requirements. If your application is meant to be cross-platform, then in general I wouldn’t suggest trying to alter your app’s output to enforce a particular End-Of-Line (EOL) format. Instead, you could just normalize EOLs in the strings before comparing them in your tests. I haven’t used it before, but it looks like this package can help.