[英]Expect libarary TypeError: expect(...).toInclude is not a function
I'm guessing it's an import error somehow, but I can't seem to figure out how, expect is up to date and I can't get it too run without it saying我猜这是一个不知何故的导入错误,但我似乎无法弄清楚如何,期望是最新的并且我无法在没有它说的情况下运行它
libarary TypeError: expect(...).toInclude is not a function
库 TypeError: expect(...).toInclude 不是一个函数
var request = require("supertest");
var {app} = require("./../server.js");
var {Show} = require("./../models/show");
var expect = require('expect');
describe("GET /show/:id", () => {
it("Should include the show name 'Arrow' in the body", (done) => {
request(app)
.get(`/show/${showName}`)
.expect(200)
.expect((res) => {
expect('hello world').toInclude('world')
})
.end(done);
});
})
});
UPDATE : besides .toMatchObject
, you can also use .toHaveProperty
更新:除了
.toMatchObject
,您还可以使用.toHaveProperty
For anyone who used .toInclude
to check if an object contains certain fields, the new version is .toMatchObject
.对于任何使用
.toInclude
检查对象是否包含某些字段的人来说,新版本是.toMatchObject
。
The expect
library was recently made part of the Jest project - the Jest team changed the API a little, as this answer explains. expect
库最近成为Jest项目的一部分——Jest 团队对 API 做了一些改动,正如这个答案所解释的那样。
The full documentation for expect
can now be found here: https://facebook.github.io/jest/docs/en/expect.html现在可以在此处找到
expect
的完整文档: https ://facebook.github.io/jest/docs/en/expect.html
If you are facing similar problem than it can be solved by importing jest-dom
in your test file: import '@testing-library/jest-dom'
in your xyz.test.js
如果您遇到类似的问题,可以通过在测试文件中导入
jest-dom
来解决:在xyz.test.js
中import '@testing-library/jest-dom'
Don't forget to install
jest-dom
in order to use it with jest:不要忘记安装
jest-dom
以便与 jest 一起使用它:
npm i --save-dev @testing-library/jest-dom
Hope it helps.. :)希望能帮助到你.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.