开玩笑 - expect(...).toContainEqual 不是一个函数

Jest - expect(...).toContainEqual is not a function

我正在使用 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) and toBeInstanceOf was merged on Sep. 7th (https://github.com/facebook/jest/pull/1625) 合并。然而,v15.1.1 于 9 月 2 日发布。

Jest 的 API 页面似乎应该更改,这样未发布的 API 就不会被包含在内。