Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expect assertions type error -> expect(...).toExist is not a function

I'm testing a NodeJS app. I encountered this error when I ran the tests. The test script is below:

.expect((res) => {
    expect(res.headers['x-auth']).toExist();
    expect(res.body._id).toExist();
    expect(res.body.email).toBe(email);
})

The error showed:

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

How can I resolve this issue?

like image 266
Md Ashiqur Rahman Avatar asked Sep 26 '17 23:09

Md Ashiqur Rahman


People also ask

What is expect assertions in jest?

expect. assertions(number) will verify that a certain number of assertions are called during a test. Often, this is useful when testing asynchronous code, so as to make sure that assertions in a callback actually got called.

What is expect in JS?

expect(value) ​ The expect function is used every time you want to test a value. You will rarely call expect by itself. Instead, you will use expect along with a "matcher" function to assert something about a value. It's easier to understand this with an example.


1 Answers

The expect assertion library has changed ownership. It was handed over to the Jest team, who in their infinite wisdom, created a new API.

You must now use toBeTruthy()instead of toExist().

You can still install expect as before, npm install expect --save-dev, which is currently at version 21.2.1. Most methods names will remain unchanged except for a few, including toExist().

like image 158
AKenny Avatar answered Sep 19 '22 01:09

AKenny