Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Error after running the test case

Expected: StringContaining "[3] find needle in the haystack
[2] water the plants
[1] the thing i need to do
"
Received: "[3] find needle in the haystack·
[2] water the plants·
[1] the thing i need to do·

"
Test case code:

JavaScript


test("list todos in reverse order (added latest first)", () => {
let todos = [
"the thing i need to do",
"water the plants",
"find needle in the haystack",
];
todos.forEach((todo) => execSync(todoTxtCli("add", `"${todo}"`)));
let expected = `[3] find needle in the haystack
[2] water the plants
[1] the thing i need to do
`;
let received = execSync(todoTxtCli("ls")).toString("utf8");
expect(received).toEqual(expect.stringContaining(expected));
});

What I have tried:

I am trying to run a bunch of test cases and this particular one fails but the expected output is the same as the received output except the "·" after every line. Why "·" shows up after every line in testing even though when I run the program it doesn't. I have attached the output below.
Posted
Updated 20-Dec-20 0:17am
Comments
Richard MacCutchan 19-Dec-20 4:49am    
The added strings and the test strings are different.

Look at your error report: the each line of the "Received" data has an extra character at the right hand end which isn't present in the "Expected" data.
This is probably why it fails.

So go back to the code you are testing in the debugger and look to see exactly what it is returning, then you can start finding out why.

Sorry - but we can't do that for you!
 
Share this answer
 
I have the exact same problem and for the exact same question.

The issue is due to the newline character. I am writing my code in C. When the javascript code receives the string it is appending the "dot" along with the newline. Why? I don't understand that. I just know that it's doing that.

If anyone knows please help.
 
Share this answer
 
Comments
GenJerDan 21-Dec-20 5:03am    
Me, if I was sure the extra characters were non-text/non-printable, I'd add a "trim" in there somewhere to remove all extraneous characters from the ends. That's cheating, of course.
i am able to understand your problem, and i have a solution for this too...

can u explain me more what are u doing??
 
Share this answer
 
Comments
Richard MacCutchan 19-Dec-20 11:47am    
If you have a solution then please post it.
Are you able to delete text in the file??
 
Share this answer
 
Comments
Richard MacCutchan 20-Dec-20 7:45am    
This is not an answer, and has nothing to do with the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900