Testing 如何使用jasmine和量角器在通过的测试上编写自定义消息?

Testing 如何使用jasmine和量角器在通过的测试上编写自定义消息?,testing,jasmine,protractor,Testing,Jasmine,Protractor,我正在寻找一种方法来添加自定义消息成功的测试与量角器和茉莉花。 有很多方法可以自定义失败时的消息,如jasmine自定义消息节点包或简单地: expect(column.get(0)).toEqual("7", "This is not something I've expected"); 但是我还没有找到一种方法来添加关于成功的自定义消息。我正在使用dragrator-jasmine2-html-reporter生成报告,但是成功的测试只显示“通过”或“0失败”消息,我想更明确地说明我正在测

我正在寻找一种方法来添加自定义消息成功的测试与量角器和茉莉花。 有很多方法可以自定义失败时的消息,如jasmine自定义消息节点包或简单地:

expect(column.get(0)).toEqual("7", "This is not something I've expected");

但是我还没有找到一种方法来添加关于成功的自定义消息。我正在使用dragrator-jasmine2-html-reporter生成报告,但是成功的测试只显示“通过”或“0失败”消息,我想更明确地说明我正在测试什么以及测试通过的原因。

您想为Jasmine编写一个自定义匹配器。您希望将它们包含在dragrator.conf.js文件中,以便在整个项目中都可以访问它们

下面是一个在出现错误时将数字与消息打印关闭进行比较的示例。如果运行此命令,则错误将是
预期7到8(预期错误)
。注意,这是使用每个之前的
将其包含在规范中

var customMatchers = {
  toBeEqualWithMessage: function(util, customEqualityTesters) {
    return {
      compare: function(actual, expected, message) {
        var result = {};
        result.pass = util.equals(actual, expected, customEqualityTesters);
        if (!result.pass) {
          result.message = "Expected " + actual + " to be " + expected + " (" + message + ")";
        }
        return result;
      }
    };
  }
};

describe('Custom Matcher', function(){
  beforeEach(function() { jasmine.addMatchers(customMatchers);});

  it('should use a matcher', function(){
    expect(7).toBeEqualWithMessage(7,"No error because they match");
    expect(7).not.toBeEqualWithMessage(8,"No error because of the 'not'");
    expect(7).toBeEqualWithMessage(8,"Expected Error");
  });
});

仅供参考:doc有一个result.message用于一个通过的案例,但我不知道它在哪里使用,可能是一个详细的打印输出。

您想为Jasmine编写一个自定义匹配器。您希望将它们包含在dragrator.conf.js文件中,以便在整个项目中都可以访问它们

下面是一个在出现错误时将数字与消息打印关闭进行比较的示例。如果运行此命令,则错误将是
预期7到8(预期错误)
。注意,这是使用每个之前的
将其包含在规范中

var customMatchers = {
  toBeEqualWithMessage: function(util, customEqualityTesters) {
    return {
      compare: function(actual, expected, message) {
        var result = {};
        result.pass = util.equals(actual, expected, customEqualityTesters);
        if (!result.pass) {
          result.message = "Expected " + actual + " to be " + expected + " (" + message + ")";
        }
        return result;
      }
    };
  }
};

describe('Custom Matcher', function(){
  beforeEach(function() { jasmine.addMatchers(customMatchers);});

  it('should use a matcher', function(){
    expect(7).toBeEqualWithMessage(7,"No error because they match");
    expect(7).not.toBeEqualWithMessage(8,"No error because of the 'not'");
    expect(7).toBeEqualWithMessage(8,"Expected Error");
  });
});

仅供参考:文档中有一个结果。消息用于通过的案例,但我不知道在哪里使用,可能是详细的打印输出。

不幸的是,jasmine中没有内置用于此目的的内容:……不幸的是,jasmine中没有内置用于此目的的内容:……此自定义匹配器如何帮助显示成功消息?看起来它的工作方式与通常的匹配器相同,仅在失败时显示消息。请详细解释。此自定义匹配器如何帮助显示成功消息?看起来它的工作方式与通常的匹配器相同,仅在失败时显示消息。请详细解释。