开玩笑的魔术数量比较失败了... tobe
我正在测试以确保buffer
的魔术数字是zip
格式。
我是通过提取缓冲区的第一个4个字节来串起的,并与pk
的魔术数进行比较。
const zipMagicNumber: string = 'PK'
const uploadedMagicNumber: string = uploadMock.mock.calls[0][0].Body.subarray(0, 4).toString()
expect(zipMagicNumber).toBe(uploadedMagicNumber)
但是测试失败了:
expect(received).toBe(expected) // Object.is equality
Expected: "PK"
Received: "PK"
这些都是相同的值,并且都是字符串。我想念什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些隐藏的字符引起了比较错误,因此,对于可读性,我移至使用十六进制比较,现在已经通过了:
Some hidden characters were causing the comparison error, so for legibility I moved to using hex comparisons instead and now it's passing: