我在我的代碼中添加了一個功能,但是當我運行所有測驗時,所有測驗都成功運行,但 Jest 仍然拋出一個內部錯誤并顯示此訊息:
Ran all test suites.
the_path\node_modules\expect\build\index.js:303
throw error;
^
JestAssertionError: expect(received).toBe(expected) // Object.is equality
Expected: "node-user-settings"
Received: "null"
我創建了另一個 .js 檔案并呼叫了我想用 Jest 測驗的代碼,它運行正常。現在,我不明白為什么 Jest 會拋出內部錯誤。
這是產生錯誤的測驗。
test("asynchronously gets a value, using callbacks without optional filename", () => {
settings.getState_c("moduleName", null, null, (err, data) => {
expect(err).toBe(null);
expect(data).toBe("node-user-settings");
});
});
uj5u.com熱心網友回復:
我認為您需要告訴 Jest 您正在測驗異步函式:https ://jestjs.io/docs/asynchronous 。
如果您的函式不回傳 Promise,而是異步的,請使用doneinstead of 。async
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/537328.html
上一篇:如何唯一陣列物件值?
下一篇:Node.js發布資料
