简体   繁体   English

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

[英]Jest - expect(…).toContainEqual is not a function

I am using Jest to test my Node.JS application and when I run my tests, some built-in functions don't work, it seems like they are not defined. 我正在使用Jest测试我的Node.JS应用程序,当我运行我的测试时,一些内置函数不起作用,似乎它们没有被定义。 For instance, toContainEqual and toBeInstanceOf . 例如, toContainEqualtoBeInstanceOf

Here is example of my code: 这是我的代码示例:

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

And the error I'm getting: 而我得到的错误:

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

But the other functions (like toEqual , toBeTruthy ) work fine though. 但其他功能(如toEqualtoBeTruthy )工作正常。

I am using Jest v15.1.1 (according to jest -v ). 我正在使用Jest v15.1.1(根据jest -v )。

How can I deal with it? 我怎么处理它?

toContainEqual and toBeInstanceOf is NOT included in v15.1.1 yet. toContainEqualtoBeInstanceOf不包括在v15.1.1呢。 To use these 2 matchers, you need to install jest@15.2.0-alpha.c681f819, or just wait for the next release. 要使用这两个匹配器,您需要安装jest@15.2.0-alpha.c681f819,或者只是等待下一个版本。

According to the Jest code history, toContainEqual was merged on Sep. 20th ( https://github.com/facebook/jest/pull/1706 ) and toBeInstanceOf was merged on Sep. 7th ( https://github.com/facebook/jest/pull/1625 ). 根据Jest代码历史记录, toContainEqual于9月20日合并( https://github.com/facebook/jest/pull/1706 )并且toBeInstanceOf于9月7日合并( https://github.com/facebook/开玩笑/拉/ 1625 )。 However, v15.1.1 was released on Sep. 2th. 但是,v15.1.1于9月2日发布。

It seems the API page of Jest should be changed, so that un-released API won't be included. 似乎应该更改Jest的API页面,以便不包含未发布的API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM