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

谁都会走 提交于 2019-12-21 08:26:07

问题


I'm testing a nodejs app. Where I find this error when I run the test. 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?? TIA.


回答1:


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()'.




回答2:


If you are using Jest you can also use 'toBeDefined()'



来源:https://stackoverflow.com/questions/46437186/expect-assertions-type-error-expect-toexist-is-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!