0
我想測試使用玩笑......這個方法應該返回Promise.reject()的方法。預計一個說法叫
這裏是我寫的代碼:
test('testing Invalid Response Type',() => {
const client = new DataClient();
client.getSomeData().then(response => {
console.log("We got data: "+ response);
}).catch(e => {
console.log("in catch");
expect(e).toBeInstanceOf(IncorrectResponseTypeError);
});
expect.assertions(1);
});
當我運行測試,它打印「漁獲」,但失敗與此異常: 預計一個斷言被稱爲卻收到零個斷言電話。
console.log src/data/dataclient.test.js:25
in catch
● testing Invalid Response Type
expect.assertions(1)
Expected one assertion to be called but received zero assertion calls.
at extractExpectedAssertionsErrors (node_modules/expect/build/extract_expected_assertions_errors.js:37:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
看起來你是不是具有匹配的錯誤類型。 (你發現了一個錯誤,但它不是'IncorrectResponseTypeError'類型) –
也許你可以嘗試在控制檯中記錄'e'來查看它實際上是什麼類型 –