Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda