开玩笑-期待(…).toContainEqual不是一个函数



我正在使用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

但其他功能(如toEqual, toBeTruthy)工作良好。

我正在使用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就不会被包括在内了。

最新更新