簡體   English   中英

期望庫 TypeError: expect(...).toInclude 不是一個函數

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

這是文檔參考

expect庫最近成為Jest項目的一部分——Jest 團隊對 API 做了一些改動,正如這個答案所解釋的那樣。

現在可以在此處找到expect的完整文檔: https ://facebook.github.io/jest/docs/en/expect.html

如果您遇到類似的問題,可以通過在測試文件中導入jest-dom來解決:在xyz.test.jsimport '@testing-library/jest-dom'

不要忘記安裝jest-dom以便與 jest 一起使用它:

npm i --save-dev @testing-library/jest-dom

希望能幫助到你.. :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM