- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
对于某些测试场景,我遇到了针对多个值进行测试的需求,这些值都可以。
我想做的事情如下:
expect(resultCode).toBeIn([200,409]);
当 resultCode
为 200
或 409
时,该规范应该通过。这可能吗?
已添加感谢 peter 和 dolarzo 指导我创建匹配器。我在使用 addMatchers() 时遇到了问题。所以,最后我在 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。 ( Jasmine 1.3.1)
最佳答案
为了使这样的事情有效:
expect(3).toBeIn([6,5,3,2]);
Jasmine 有一个叫做匹配器的特性:
这是一个关于如何声明它们的例子。我在最后声明了您正在寻找的方法:
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。
关于javascript - Jasmine 期待(结果代码)。toBe(200 或 409),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941343/
我想在“交互”模式下“监听”shell 输出的字符串。或者我想以某种方式模拟交互模式,这仍然允许我从 shell 监听特定的字符串。 好像interact只听用户输入(我按下的键)而不是 shell
这些字符数组在语法上有什么问题? struct NewBuiltIn{ char *CommandName[64] = "bigbluetest"; char *FunctionNam
我正在尝试使用继承来创建一个从 runtime_error 派生的类,但我一直收到错误,即使这是练习中使用的确切代码并且作为书中的示例。这是代码: class DivideZeroEx : publi
您好,下面是我的 SQL 代码,它给了我错误,我不知道为什么。如果有人可以提供帮助。 select time_dif, count(time_dif) as count from ( select d
我想在构造函数中分配我的类变量,但出现错误“期望成员声明” class YLAService { var context:Context?=null class YLAService
试图让我了解 Jasmine spy ,这就是我的测试的样子: $scope.switchTurns = function () { $scope.playerTurn = !$scope
我正在研究一个 C 输出问题: #include int main() { int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12}; int i=-1;
我正在为我的大学做一个关于编译器的作业,这是我第一次使用 SableCC 3.7。我正在尝试定义我的语法文件,但是当我尝试运行它(通过命令行)时,我收到此错误: “ParserException:[5
我正在尝试下面的线性回归 python 代码,但收到错误:“期望 2D 数组得到 1D 数组:Array=[16]”。可能出了什么问题? from sklearn.linear_model impo
这个问题在这里已经有了答案: MySQL - UPDATE query based on SELECT Query (13 个答案) 关闭 3 年前。 我尝试将 John Smith 的薪水增加 1
我在程序结束时遇到问题,它在关键字“END”的末尾表示语法错误,意外的 END_OF_INPUT,期待 IF - 最后一行。我看不出出了什么问题,有人知道问题出在哪里 DELIMITER $$
我为我的方法编写了一个 JUnit 测试。 这是我的方法: public static int delimit(int value, int min, int max) throws Illeg
我想制作一个可以使用 srand 函数回答问题的 expect 脚本。 例如,我将使用 netcat 连接到服务器,我将从服务器收到一个问题,例如“请输入 0 或 1”;然后我希望我的脚本可以使用上面
我有一个初始化脚本(我运行的是 Debian)来启动一个 DLNA 服务器。当我开始服务时,出现以下错误。任何帮助,将不胜感激。请注意:我对 linux/bash/debian 非常陌生。 我收到此错
我正在尝试创建一个脚本来清除 ciscoasa bad xlate。 为了检查错误的 xlate,我运行 sh xlate |在 500 中,如果它得到回复,那么它应该发送一个明确的命令。如果我不这样
我在使用 bash 变量执行 expect 命令时遇到问题。我有脚本参数给定的位置,我需要通过 expect -c 在发送命令中使用它。但我需要用 "给它,所以实际上发送命令认为我已经结束输入,并且在
我真的很难过!我不想使用 RSA AUTH,所以请弃权。 #!/bin/bash echo "Enter the server password" read password cd /home/mik
我有一个异步 QUnit 测试,如果操作超时,测试应该通过。 (我正在测试,如果您省略可选的 errorCallback 并执行会引发错误的操作,那么无论您等待多长时间,基本上都不会发生任何事情。)
关于这个话题有很多问题,但是 - 他们没有给我答案。 根据建议 - 有一个可以设置 ServicePointManager.Expect100Continue = false。但这是 Not Acce
有几篇关于相同内容的帖子,但我仍然无法使我的 expect 脚本正常工作。我的意图是将所有内容自动化,但为用户保留输入密码。所以脚本有 3 个部分: 自动登录 让用户输入密码 将控制权交还给 Expe
我是一名优秀的程序员,十分优秀!