I have a method that produces a multi-line string as shown below:
line 1 of example
line 2 of example
line 3 of example
and I want to be able to write my code like this:
it('should return the correct output', () => {
expect(service.getData('bar').toEqual(
`line 1 of example
line 2 of example
line 3 of example`);
});
but unfortunately, it results in an error due to extra whitespace before some lines being added by the test:
Expected 'line 1 of example
line 2 of example
line 3 of example' to equal 'line 1 of example
line 2 of example
line 3 of example'.
I am aware that I can manually adjust my tests by including newline characters or removing the whitespace, but it is not visually appealing.
It would be great if there was a tool available for stripping out unnecessary indentations like this in a safe and reliable manner. Is there such a utility, do I need to create my own solution, or should I stick with using newline characters?