# AssertionError when comparing bodies with new lines

**URL:** <https://community.postman.com/t/assertionerror-when-comparing-bodies-with-new-lines/49770>\
**Category:** Help Hub\
**Created:** [July 20, 2023, 12:20pm UTC](https://community.postman.com/t/assertionerror-when-comparing-bodies-with-new-lines/49770 "2023-07-20T12:20:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghiandoni.g](https://avatars.discourse-cdn.com/v4/letter/g/6f9a4e/32.png) [@ghiandoni.g](https://community.postman.com/u/ghiandoni.g)\
**Post date:** [July 20, 2023, 12:20pm UTC](https://community.postman.com/t/assertionerror-when-comparing-bodies-with-new-lines/49770/1 "2023-07-20T12:20:26Z")

</div>

Hello,

I am testing an API that produces a body response with new lines, precisely, I am testing an example that returns this block (also with empty lines at the top and bottom)

```auto

  SciTegic07202312172D

  0 0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 6 6 0 0 0
M V30 BEGIN ATOM
M V30 1 C 0 2 0 0
M V30 2 C -0.866 1.5 0 0
M V30 3 C -0.866 0.5 0 0
M V30 4 C 0 0 0 0
M V30 5 C 0.866 0.5 0 0
M V30 6 C 0.866 1.5 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 2 1 2
M V30 2 1 2 3
M V30 3 2 3 4
M V30 4 1 4 5
M V30 5 2 5 6
M V30 6 1 6 1
M V30 END BOND
M V30 END CTAB
M END

```

I have tried using the assertion function as follows - by escaping the new lines with \n:

pm.test(“Response Test”, function() {  
pm.response.to.have.body(“\nSciTegic07202312172D\n\n0 0 0 0 0 0 999 V3000\nM V30 BEGIN CTAB\nM V30 COUNTS 6 6 0 0 0\nM V30 BEGIN ATOM\nM V30 1 C 0 2 0 0\nM V30 2 C -0.866 1.5 0 0\nM V30 3 C -0.866 0.5 0 0\nM V30 4 C 0 0 0 0\nM V30 5 C 0.866 0.5 0 0\nM V30 6 C 0.866 1.5 0 0\nM V30 END ATOM\nM V30 BEGIN BOND\nM V30 1 2 1 2\nM V30 2 1 2 3\nM V30 3 2 3 4\nM V30 4 1 4 5\nM V30 5 2 5 6\nM V30 6 1 6 1\nM V30 END BOND\nM V30 END CTAB\nM END\n”)  
});

However, my test fails without explaining what differences there are between response and expected result:

Response Test | AssertionError: expected response body to equal ‘\nSciTegic07202312172D\n\n0 0 0 0 …’ but got ‘\n SciTegic07202312172D\n\n 0 0 0…’

It just raises an AssertionError. I am using Postman June 2023 (v10.15).

I checked already checked:

> <https://github.com/postmanlabs/postman-app-support/issues/9020>
>
> With earlier versions of Postman the formatting of body text was not changed on …saving a request.
> With the latest version when message body to be sent contains text across multiple rows then Postman reformats the text to append "\\n" new line characters after all carriage returns ("\\r" characters).
> 
> For context these are HL7 messages used within the healthcare industry which cannot accept new line characters.
> 
> \*\*Steps to reproduce:\*\*
> 1. Create a new POST request and enter message Body as per example below (raw Text)
> 
> \`\`\`
> MSH|^~\\\\&|Test||WPE||20200227111520||OUL^R21|987654321|P|2.4
> PID|||1231231254^^^^NHS||TestSurname^TESTPATIENTForename||19810622|F
> SAC||12345
> ORC|SC||12345||IP||||||||||||||||||||PRINTED
> OBR|1||12345|SLIDE^StatusUpdate||||||||||||||||12345||||||||||||||testuser^User^Test
> \`\`\`
> 
> 2. Save the request
> 3. Send the request
> 
> \*\*Expected:\*\*
> Message body sent matches what was originally entered.
> 
> \*\*Actual:\*\*
> "\\n" new line characters are added after each carriage return, causing message validation issues.
> 
> \`\`\`
> MSH|^~\\\\&|Test||WPE||20200227111520||OUL^R21|987654321|P|2.4\\r\\n
> PID|||1231231254^^^^NHS||TestSurname^TESTPATIENTForename||19810622|F\\r\\n
> SAC||12345\\r\\n
> ORC|SC||12345||IP||||||||||||||||||||PRINTED\\r\\n
> OBR|1||12345|SLIDE^StatusUpdate||||||||||||||||12345||||||||||||||testuser^User^Test
> \`\`\`

> [@Postman fails to assert long string in response value](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/5):
>
> This behaviour looks similar to the issue reported here: [Raw text when saved as request message body has new line characters ("\n") appended after each carriage return · Issue #9020 · postmanlabs/postman-app-support · GitHub](https://github.com/postmanlabs/postman-app-support/issues/9020) As a workaround, can you try removing '\r\n’before test script, i.e. var textData = pm.response.text(); textData = textData.replace(’\r\n’, ‘’); pm.expect(textData).to.eql(environment.fileVar); Please let me know if that works for you @yippie as well …

Thanks,
