【问题标题】:What is the name of the unit test naming convention that is prefixed with "#" and "." in the test names?以“#”和“.”为前缀的单元测试命名约定的名称是什么?在测试名称中?
【发布时间】:2021-12-14 13:37:47
【问题描述】:

我看过一些这样写的测试,我想知道是否有人知道这个约定的名称:

describe("users/domains/services/user-service", () => {
  describe("UserService", () => {
    describe(".create()", () => {
      ...
    });

   describe(".update()", () => {
      ...
   });
    
    // Static method
    describe("#new()", () => {
      ...
    });
  });
});

如果有人可以帮助我,我将非常感激。

【问题讨论】:

标签: javascript node.js unit-testing mocha.js chai


【解决方案1】:

这种引用方法或变量的方式来自jsdoc,称为namepath。例如,MyClass#myMethod 可用于文档注释中,以引用名为 MyClass 的类中名为 #myMethod 的方法。

mocha.js documentation 中使用这种约定进行 JavaScript 测试非常突出。 betterspecs.orgbetterspecs.org 的等效样式也是 Ruby 中的最佳实践,还有 some discussion about it。我不知道是谁首先采用了这种风格,我认为它没有名字。

this related StackOverflow question 中有一些更相关的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 2012-08-06
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多