gpt4 book ai didi

Jasmine:如何检查数组是否包含对象?

转载 作者:行者123 更新时间:2023-12-02 02:21:25 26 4
gpt4 key购买 nike

此检查曾经通过:

expect(array).toContain(value)

数组:

[
{"_t":"user","id":1073970419,"email":"email3@example.org","name":"Spectator"},
{"_t":"user","id":4464992042,"email":"email4@example.org","name":"Collaborator"},
{"_t":"user","id":1978569710,"email":"email5@example.org","name":"Manage"}
]

值:

{"_t":"user","id":1978569710,"email":"email5@example.org","name":"Manage"}

但不再过去了。编写相同测试的新方法是什么?

最佳答案

您需要的语法是:

const obj = {"_t":"user","id":1978569710,"email":"email5@example.org","name":"Manage"};

expect(array).toContain(jasmine.objectContaining(obj));

参见 fiddle :https://jsfiddle.net/bblackwo/4o5u5Lmo/16/

关于Jasmine:如何检查数组是否包含对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39411424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com