啊,可怕的token o
。它正在从[object Object]
读取'o',它是普通Ol'JavaScript对象的toString
表示形式。
您可以通过输入JavaScript REPL和:
08:54 $ node
Welcome to Node.js v13.0.1.
Type ".help" for more information.
> JSON.parse({}.toString())
Thrown:
SyntaxError: Unexpected token o in JSON at position 1
> ({}).toString()
'[object Object]'
因此,将来,只要您看到该错误,就知道您已跳过在某个地方进行字符串化的步骤!
这里的窍门是readFile
返回一个对象(不是字符串,JSON文件为parsed by Cypress into JavaScript),但是您正在对该对象调用JSON.parse
。
尝试一下:
cy
.readFile('data2.json')
.then(data2 => cy.readFile('data.json').should('deep.equal',data2))
请注意此处使用deep.equal
,因为我们正在比较对象。
本文链接:https://www.f2er.com/3081575.html