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

Jasmine expect(resultCode).toBe(200 or 409)

Jasmine expect(resultCode).toBe(200 or 409)(Jasmine expect(resultCode).toBe(200 or 409))
本文介紹了Jasmine expect(resultCode).toBe(200 or 409)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

對于某些測試場景,我需要針對多個值進行測試,這些值都可以.

For some test scenarios I run into the need of testing against multiple values which are all OK.

我想做的事情如下:

expect(resultCode).toBeIn([200,409]);

resultCode200409 時,此規(guī)范應通過.這可能嗎?

This spec should pass when resultCode is either 200 or 409. Is that possible?

添加感謝 peter 和 dolarzo 指導我創(chuàng)建匹配器.我遇到了 addMatchers() 的問題.所以,最后我在 jasmine.js 中添加了以下內容:

ADDED Thanks to peter and dolarzo for pointing me towards creating matchers. I had problems with addMatchers(). So, in the end I added the following to the jasmine.js:

jasmine.Matchers.prototype.toBeIn = function (expected) {
    for (var i = 0; i < expected.length; i++)
        if (this.actual === expected[i])
            return true;
    return false;
};

這給了我一個可行的解決方案.我現在可以根據需要做 toBeIn.(茉莉花1.3.1)

This gave me a working solution. I can now do the toBeIn as needed. (Jasmine 1.3.1)

推薦答案

為了做這樣的事情:

 expect(3).toBeIn([6,5,3,2]);

Jasmine 有一個稱為匹配器的功能:

Jasmine has a feature called matchers:

這是一個關于如何聲明它們的示例.我在最后聲明了您正在尋找的方法:

This is an example on how to declare them. I have declared at the very end the method you are looking for:

describe('Calculator', function(){
    var obj;
    beforeEach(function(){
        //initialize object
        obj = new Object();

        jasmine.addMatchers({
            toBeFive: function () {
                return {
                    compare: function (actual, expected) {
                        return {
                            pass: actual === 5,
                            message: actual + ' is not exactly 5'
                        }
                    }
                };
            },
            toBeBetween: function (lower,higher) {
                return {
                    compare: function (actual, lower,higher) {
                        return {
                            pass: ( actual>= lower   && actual <= higher),
                            message: actual + ' is not between ' + lower + ' and ' + higher
                        }
                    }
                };
            },
            toBeIn: function(expected) {
                    return {
                        compare: function (actual, expected) {
                            return {
                                pass: expected.some(function(item){ return item === actual; }),
                                message: actual + ' is not in ' + expected
                            }
                        }
                    };
                }
        });


    });

這是你需要的匹配器:

toBeIn: function(expected) {
                    return {
                        compare: function (actual, expected) {
                            return {
                                pass: expected.some(function(item){ return item === actual; }),
                                message: actual + ' is not in ' + expected
                            }
                        }
                    };
                }

重要與 jasmine 2.0.我必須將 jasmine.addMatchers({ 與 jasmine specrunner.html 一起使用,但是當我使用 Karma 對其進行配置時,我必須將 jasmine 替換為 this 之類的this.addMatchers({ 因為 Karma 使用早期版本的 Jasmine.

Important with jasmine 2.0. I had to use jasmine.addMatchers({ with jasmine specrunner.html but when I configured it with Karma I had to replace jasmine with this like this.addMatchers({ because Karma use an earlier version of Jasmine.

這篇關于Jasmine expect(resultCode).toBe(200 or 409)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發(fā)技術
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 - 如何監(jiān)視函數中的函數調用?)
主站蜘蛛池模板: 香蕉久久a毛片 | 九九色综合 | 久久97精品| 91精品国产综合久久福利软件 | 久久精品一区二 | 国产91在线播放精品91 | 色又黄又爽网站www久久 | 久久最新 | 国产精品久久午夜夜伦鲁鲁 | 狠狠久 | 日韩欧美亚洲 | 国产精品欧美一区喷水 | 亚洲一区在线日韩在线深爱 | 九九热精品在线视频 | 国产精品一区二区视频 | 国产亚洲第一页 | 欧美精品1区2区3区 免费黄篇 | 91 视频网站 | 欧美高清性xxxxhd | 青青草综合 | 亚洲国产日韩一区 | 久久精品99 | h视频在线播放 | 中文字幕视频在线 | 伊人超碰| 国内精品视频在线观看 | 亚洲在线高清 | 欧美a级成人淫片免费看 | 91精产国品一二三区 | 高清国产一区二区 | 欧美a级网站 | 人人做人人澡人人爽欧美 | 91精品国产一区二区三区香蕉 | 欧美精品v国产精品v日韩精品 | 日日干日日操 | 丝袜美腿一区二区三区 | 久久蜜桃av | 伊人91在线| 国产亚洲精品成人av久久ww | 日本免费在线 | 精品一二 |