我有如下代码
expect(insertedData).toEqual({
id: expect.any(String),
clientId: 'client1',
...
我希望 id 应该匹配任何字符串,但我得到的结果是
不知道我错过了什么。
我也像下面一样使用仍然相同的错误
expect(insertedData).toEqual(expect.objectContaining({
这发生在我身上。事实证明,问题不在于 Expect.any() 的字段,而在于其他字段。似乎那里的差异很糟糕。
你的表达问题依赖于第一个期望,即
toEqual()
期望应该使用toMatchObject,例如:
expect(insertedData).toMatchObject({...