# Postman fails to assert long string in response value

**URL:** <https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786>\
**Category:** Help Hub\
**Created:** [October 15, 2020, 8:08am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786 "2020-10-15T08:08:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yippie](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@yippie](https://community.postman.com/u/yippie)\
**Post date:** [October 15, 2020, 8:08am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/1 "2020-10-15T08:08:11Z")

</div>

How to assert response value with long string?

In our API design, the response contains multiple elements with base64 binary string values, which can be real long (e.g. 135,000 characters, or more), and I think this is causing the assertion failure.

This is a snippet of my test:  
pm.test(“expected file”, () =\> {  
const responseJson = pm.response.json();  
pm.expect(responseJson.result.file).to.eql(“JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QYWdlcy9LaWRzWz… _the rest is truncated, up to ~135k characters_…”);  
});

Have I done anything wrong or is there any way to get around this issue?

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [October 20, 2020, 7:31pm UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/2 "2020-10-20T19:31:19Z")

</div>

Can you please share a complete example? I don’t see a reason why this would fail, IF the data is actually equal.

---

<div class="post-metadata">

**Author:** ![yippie](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@yippie](https://community.postman.com/u/yippie)\
**Post date:** [October 21, 2020, 10:43am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/3 "2020-10-21T10:43:27Z")

</div>

That is the actual test function I’ve added. I cannot paste the full 135k long string to the reply as the forum doesn’t allow it but you get the idea.

The error I’m getting is:  
`expected file | AssertionError: expected 'JVBERi0xLjMKJcK1wrYK...' to deeply equal 'JVBERi0xLjMKJcK1wrYK...'`  
where the expected and actual strings are exact same.

I have also tested just comparing the ~135k long string to string like so:

`pm.expect("JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QY...with the rest of 135k characters truncated...").to.eql("JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QY...with the rest of 135k characters truncated...");`

and that works and passes as expected.

I don’t understand why when it’s comparing against the pm.response.json() value then it fails.

---

<div class="post-metadata">

**Author:** ![andrei\_m](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@andrei\_m](https://community.postman.com/u/andrei_m)\
**Post date:** [January 6, 2021, 9:41am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/4 "2021-01-06T09:41:09Z")

</div>

Hello, I am facing something similar, asserting will fail with deeply equal error, but if I’m checking both values manually, content will be identical.

var textData = pm.response.text();  
pm.expect(textData).to.eql(environment.fileVar);

Check response body | AssertionError: expected ‘“Email Address”,“Status”,“Sub Status”,“Account”,“Domain”,“First Name”,“Last Name”,“Gender”,“Free Email”,“MX Found”,“MX Record”,“Provider”,“Did You Mean”\r\n”link”,”valid”,"",“email”,”link”,””,””,””,”false”,“True”,”link”,”g-suite”,””\r\n”link”,”valid”,"",“email”,“[email.com](http://email.com)”,"","","",“false”,“True”,”link”,”qq”,””\r\n”link”,”valid”,"",“email”,”link”,””,””,””,”true”,“True”,”link”,”google”,""\r\n’ **to deeply equal** ‘“Email Address”,“Status”,“Sub Status”,“Account”,“Domain”,“First Name”,“Last Name”,“Gender”,“Free Email”,“MX Found”,“MX Record”,“SMTP Provider”,“Did You Mean” “link”,”valid","",“stuart”,”link”,””,””,””,”false”,“True”,”link”,”g-suite”,"" “link”,”valid","",“email”,“[email.com](http://email.com)”,"","","",“false”,“True”,”link”,”qq”,"" “link”,”valid","",“email”,”link”,””,””,””,”true”,“True”,”link”,”google”,""’

Looks like assertion is adding \r\n?

Printing both textData and fileVar will result in the same data.

Any other way to compare this kind of data?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 7, 2021, 1:04am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/5 "2021-01-07T01:04:50Z")

</div>

> [@andrei\_m](#):
>
> \r\n

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 🙂

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [January 7, 2021, 1:12am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/6 "2021-01-07T01:12:35Z")

</div>

@andrei_m Nearly same kind of discussion is right here, this might be useful to you.

> [@How to remove whitespace in a returned item](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/10):
>
> @praveendvd I guess it all depends what the structure of the string is - trim() only removes whitespace from the beginning and the end of a string. For example: @postnewbie2020 It looks like you have a mixture of whitespace and different carriage returns or newlines. From the image, you have provided it’s difficult to know what’s going on. Can you provide an example of the HTML page it’s looking at so it will be easier to run locally rather than taking a guess smiley

---

<div class="post-metadata">

**Author:** ![andrei\_m](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@andrei\_m](https://community.postman.com/u/andrei_m)\
**Post date:** [January 7, 2021, 12:15pm UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/7 "2021-01-07T12:15:04Z")

</div>

> [@taehoshino](#):
>
> var textData = pm.response.text();  
> textData = textData.replace(’\r\n’, ‘’);  
> pm.expect(textData).to.eql(environment.fileVar);

It worked with:  
textData = textData.replace(/\r\n/g, ‘’);

Thank you, @taehoshino & @bpricilla

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 8, 2021, 12:07am UTC](https://community.postman.com/t/postman-fails-to-assert-long-string-in-response-value/16786/8 "2021-01-08T00:07:07Z")

</div>

@andrei_m Awesome!!  
Let us know if you have any more questions - more than happy to help!
