2016-09-29 29 views
2

我使用Jest來測試我的Node.JS應用程序,當我運行我的測試時,一些內置函數不起作用,看起來像是沒有定義的。例如,toContainEqualtoBeInstanceOfJest - expect(...)。toContainEqual不是一個函數

這裏是例如我的代碼:

it('should delete DB entry',() => query(url, queryString) 
    .then(res => res.json() 
    .then(() => db.collection('exercises').find({}).toArray())) 
    .then(res => expect(res).toContainEqual(originalExercise))) 

而我得到的錯誤:

TypeError: expect(...).toContainEqual is not a function 

但其他功能(如toEqualtoBeTruthy)做工精細,雖然。

我使用的是Jest v15.1.1(根據jest -v)。

我該如何處理?

回答

7

toContainEqual and toBeInstanceOf is not included in v15.1.1 yet。要使用這兩個匹配器,您需要安裝[email protected],或者等待下一個版本。

按照玩笑碼歷史,toContainEqual是9月20日(https://github.com/facebook/jest/pull/1706)和toBeInstanceOf合併被合併了9月7日(https://github.com/facebook/jest/pull/1625)。但是,v15.1.1於9月2日發佈。

看來Jest的API頁面應該改變,所以未發佈的API將不會被包含。