在Jasmine 1.3中添加自定义匹配器 - 显示未定义

时间:2015-09-24 13:41:17

标签: javascript testing jasmine protractor end-to-end

我正在使用带有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;
            },
        });
    });

请注意,我没有改变他们的例子。 在那之后,我尝试在" it"中使用它。那样:

expect({ "hyuk": "j" }).toBeGoofy();

我收到一个错误:

TypeError: undefined is not a function

在匹配器上使用的行上.. 有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

问题显然是匹配器的定义。 而不是:

SET @date = '2013-05-03 10:05:00';
SET @allign = '1_QUARTER';
SELECT
   CAST(@date AS DATETIME) AS Date,
   CASE @allign
     WHEN '1_YEAR' THEN  DATE_FORMAT(@date ,'%Y-01-01 00:00:00')
     WHEN '1_QUARTER' THEN  (CASE EXTRACT(QUARTER FROM @date)
                              WHEN 1 THEN DATE_FORMAT(@date ,'%Y-01-01 00:00:00')
                              WHEN 2 THEN DATE_FORMAT(@date ,'%Y-04-01 00:00:00')
                              WHEN 3 THEN DATE_FORMAT(@date ,'%Y-07-01 00:00:00')
                              WHEN 4 THEN DATE_FORMAT(@date ,'%Y-10-01 00:00:00')
                              ELSE NULL END)
     WHEN '1_MONTH' THEN DATE_FORMAT(@date ,'%Y-%m-01 00:00:00')
     WHEN '1_DAY' THEN  DATE_FORMAT(@date ,'%Y-%m-%d 00:00:00')
     ELSE NULL
     END AS Alligned;

这条消息应该是一个包含2条消息的数组,第一条用于传递,第二条用于not.matcher,所以它会是这样的:

{{1}}