I'm testing to ensure a Buffer's magic number is zip format.
I'm doing this by extracting the buffer's first 4 bytes to string and comparing against the magic number for zip which is PK.
const zipMagicNumber: string = 'PK'
const uploadedMagicNumber: string = uploadMock.mock.calls[0][0].Body.subarray(0, 4).toString()
expect(zipMagicNumber).toBe(uploadedMagicNumber)
But the test is failing with:
expect(received).toBe(expected) // Object.is equality
Expected: "PK"
Received: "PK"
These are the both the same values and are both strings. Am I missing something?
Some hidden characters were causing the comparison error, so for legibility I moved to using hex comparisons instead and now it's passing: