Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Jest toHaveBeenNthCalled escaping characters in string comparison

I'm using Jest to check the Nth call of a function, where one expected parameter is compared against a string read from a file (an HLS stream):

The expected string in question

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-KEY:METHOD=SAMPLE-AES,URI=\"skd://fairplay.entitlement.theplatform.eu/fpls/web/FairPlay\",KEYFORMAT=\"com.apple.streamingkeydelivery\",KEYFORMATVERSIONS=\"1\"

Being read in like:

const expectedClippedManifest = fs
    .readFileSync(path.resolve(__dirname, '../__test__/manifests/clipped-hls.m3u8'), 'utf-8')
    .toString()
    .trim();

(Note the \")

I compare with the output of my function using

expect(uploadS3).toHaveBeenNthCalledWith(
  1,
  'folderName',
  expectedClippedManifest, // The above string
  logger
);

And it seems Jest is adding escape characters to string - they are not equal.

Jest output

The left is expected, the right is received.

Text comparison

Console logging the string shows it is correct before being passed in to the comparison function; enter image description here

Is this intended behaviour, and is there a way of turning this off?

Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!