作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Jest 来测试我的 Node.JS 应用程序,当我运行我的测试时,一些内置函数不起作用,似乎它们没有被定义。例如,toContainEqual
和 toBeInstanceOf
。
这是我的代码示例:
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
但是其他函数(如 toEqual
、toBeTruthy
)工作正常。
我正在使用 Jest v15.1.1(根据 jest -v
)。
我该如何处理?
最佳答案
toContainEqual
和 toBeInstanceOf
尚未包含在 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/
我正在使用 Jest 来测试我的 Node.JS 应用程序,当我运行我的测试时,一些内置函数不起作用,似乎它们没有被定义。例如,toContainEqual 和 toBeInstanceOf。 这是我
我是一名优秀的程序员,十分优秀!