[英]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.