简体   繁体   中英

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. For instance, toContainEqual and toBeInstanceOf .

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.

I am using Jest v15.1.1 (according to jest -v ).

How can I deal with it?

toContainEqual and toBeInstanceOf is NOT included in v15.1.1 yet. To use these 2 matchers, you need to install jest@15.2.0-alpha.c681f819, or just wait for the next release.

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 ). However, v15.1.1 was released on Sep. 2th.

It seems the API page of Jest should be changed, so that un-released API won't be included.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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