亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

rejects.toThrow in Jest

rejects.toThrow in Jest

慕神8447489 2022-10-13 19:16:55
我創建了這個類:export class ErrorList  {      public HostelNotFoundError(details: ErrorDetail): FunctionalError {        return new FunctionalError('1', 'Can\'t find this hostel', details);    }并在服務中:throw new ErrorList().HostelNotFoundError({} });我想知道在 Jest 中是否可以執行以下操作:rejects.toThrow(HostelNotFoundError);
查看完整描述

1 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

HostelNotFoundError不是類型FunctionalError,它是類的方法,ErrorList它返回 的新實例FunctionalError。所以在你的單元測試中你必須使用:

rejects.toThrow(FunctionalError);

請注意,您可以使用toMatch來驗證錯誤消息或toMatchObject驗證錯誤的屬性:

rejects.toMatch('Can\'t find this hostel');


查看完整回答
反對 回復 2022-10-13
  • 1 回答
  • 0 關注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號