久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Jasmine 期望邏輯(期望 A OR B)

Jasmine expect logic (expect A OR B)(Jasmine 期望邏輯(期望 A OR B))
本文介紹了Jasmine 期望邏輯(期望 A OR B)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

如果滿足兩個期望之一,我需要將測試設置為成功:

I need to set the test to succeed if one of the two expectations is met:

expect(mySpy.mostRecentCall.args[0]).toEqual(jasmine.any(Number));
expect(mySpy.mostRecentCall.args[0]).toEqual(false);

我希望它看起來像這樣:

I expected it to look like this:

expect(mySpy.mostRecentCall.args[0]).toEqual(jasmine.any(Number)).or.toEqual(false);

我在文檔中遺漏了什么還是我必須編寫自己的匹配器?

Is there anything I missed in the docs or do I have to write my own matcher?

推薦答案

注意:此解決方案包含 Jasmine v2.0 之前版本的語法.有關自定義匹配器的更多信息,請參閱:https://jasmine.github.io/2.0/custom_matcher.html

Note: This solution contains syntax for versions prior to Jasmine v2.0. For more information on custom matchers now, see: https://jasmine.github.io/2.0/custom_matcher.html

Matchers.js 僅適用于單個結果修飾符" - not:

Matchers.js works with a single 'result modifier' only - not:

核心/Spec.js:

jasmine.Spec.prototype.expect = function(actual) {
  var positive = new (this.getMatchersClass_())(this.env, actual, this);
  positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
  return positive;

core/Matchers.js:

jasmine.Matchers = function(env, actual, spec, opt_isNot) {
  ...
  this.isNot = opt_isNot || false;
}
...
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
  return function() {
    ...
    if (this.isNot) {
      result = !result;
    }
  }
}

所以看起來您確實需要編寫自己的匹配器(從 beforeit 塊中獲取正確的 this).例如:

So it looks like you indeed need to write your own matcher (from within a before or it bloc for correct this). For example:

this.addMatchers({
   toBeAnyOf: function(expecteds) {
      var result = false;
      for (var i = 0, l = expecteds.length; i < l; i++) {
        if (this.actual === expecteds[i]) {
          result = true;
          break;
        }
      }
      return result;
   }
});

這篇關于Jasmine 期望邏輯(期望 A OR B)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 日本三级在线 | 久久久精品黄色 | 美女激情av| 国产精品久久久久aaaa | 一区二区三区高清 | 日韩三区 | 玖玖综合在线 | 老牛影视av一区二区在线观看 | 欧美无乱码久久久免费午夜一区 | 亚洲二区视频 | 国产精品视频在线播放 | 久在线 | 国产精品海角社区在线观看 | 日日操操 | 日韩欧美在线播放 | 久久久久99 | 国产yw851.c免费观看网站 | 日韩在线视频精品 | 亚洲国产精品一区二区久久 | 水蜜桃久久夜色精品一区 | 日韩欧美在线视频 | 欧美三级免费观看 | 天天搞夜夜操 | 精品自拍视频 | 国产在线1 | 欧美日韩视频在线第一区 | 中文字幕国产 | 男女视频在线观看网站 | 日日操夜夜操天天操 | 精品国产一区二区三区久久久蜜月 | 日韩精品一区二区三区老鸭窝 | 日韩精品一区二区三区在线观看 | 一级一片在线观看 | 日日干日日操 | 黄色片网站国产 | 亚洲国产精品激情在线观看 | av在线免费观看不卡 | 日韩中文字幕一区二区 | 亚洲精品视频免费看 | 欧美一区二区久久 | 国产农村妇女精品一区 |