【发布时间】:2015-09-24 13:41:16
【问题描述】:
我正在使用 jasmine 1.3 的量角器,尝试使用示例 here 将自定义匹配器添加到我的规范中
beforeEach(function () {
utils.log("beforeEach");
this.addMatchers({
toBeGoofy: function (expected) {
if (expected === undefined) {
expected = '';
}
var pass = this.actual.hyuk === "gawrsh" + expected;
if (pass) {
this.message = "Expected " + this.actual + " not to be quite so goofy";
} else {
this.message = "Expected " + this.actual + " to be goofy, but it was not very goofy";
}
return pass;
},
});
});
请注意,我没有对他们的示例进行任何更改。 之后,我尝试在这样的“它”中使用它:
expect({ "hyuk": "j" }).toBeGoofy();
我得到一个错误:
TypeError: undefined is not a function
在使用匹配器的那一行.. 有什么帮助吗?
【问题讨论】:
-
你把
beforeEach()块放在哪里了?谢谢。 -
@alecxe 在几个地方尝试过,在第一个“it”之前,在第一个“describe”之前,规范的结构非常简单:一个描述中的 3 个“it”。那里的日志功能也可以按预期工作和打印...
-
您确定您使用的是 jasmine v1.3 吗?如果您使用较新版本的 jasmine,通常会出现此错误。最新的是 v2.3。
标签: javascript testing jasmine protractor end-to-end