【问题标题】:Jest - expect(...).toContainEqual is not a function开玩笑 - expect(...).toContainEqual 不是函数
【发布时间】:2016-09-30 13:41:31
【问题描述】:

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

我该如何处理?

【问题讨论】:

    标签: javascript jestjs


    【解决方案1】:

    toContainEqualtoBeInstanceOf 尚未包含在 v15.1.1 中。要使用这 2 个匹配器,您需要安装 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 就不会被收录了。

    【讨论】:

      猜你喜欢
      • 2021-02-26
      • 2020-02-24
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 2020-08-24
      • 2021-03-23
      • 1970-01-01
      相关资源
      最近更新 更多