gpt4 book ai didi

javascript - 开 Jest - expect(...).toContainEqual 不是一个函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:12:21 25 4
gpt4 key购买 nike

我正在使用 Jest 来测试我的 Node.JS 应用程序,当我运行我的测试时,一些内置函数不起作用,似乎它们没有被定义。例如,toContainEqualtoBeInstanceOf

这是我的代码示例:

it('should delete DB entry', () => query(url, queryString)
.then(res => res.json()
.then(() => db.collection('exercises').find({}).toArray()))
.then(res => expect(res).toContainEqual(originalExercise)))

我得到的错误:

TypeError: expect(...).toContainEqual is not a function

但是其他函数(如 toEqualtoBeTruthy)工作正常。

我正在使用 Jest v15.1.1(根据 jest -v)。

我该如何处理?

最佳答案

toContainEqualtoBeInstanceOf 尚未包含在 v15.1.1 中。要使用这两个匹配器,您需要安装 jest@15.2.0-alpha.c681f819,或者等待下一个版本。

根据 Jest 代码历史,toContainEqual 于 9 月 20 日(https://github.com/facebook/jest/pull/1706)合并,toBeInstanceOf 于 9 月 7 日(https://github.com/facebook/jest/pull/1625)合并。然而,v15.1.1 于 9 月 2 日发布。

看来Jest的API页面应该改一下,这样未发布的API就不会被收录了。

关于javascript - 开 Jest - expect(...).toContainEqual 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39767404/

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