[英]Expect 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);
});
})
});
更新:除了.toMatchObject
,您还可以使用.toHaveProperty
对于任何使用.toInclude
检查对象是否包含某些字段的人来说,新版本是.toMatchObject
。
这是文档参考
如果您遇到类似的问题,可以通过在测试文件中导入jest-dom
来解决:在xyz.test.js
中import '@testing-library/jest-dom'
不要忘记安装
jest-dom
以便与 jest 一起使用它:
npm i --save-dev @testing-library/jest-dom
希望能帮助到你.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.