What is the purpose of Mocha's before() function?

后端 未结 3 657
轻奢々
轻奢々 2021-01-04 02:19

Mocha has several \'hooks\' to run assistive functionality in a test separate from the test cases themselves (clearing databases, creating mock files, etc).

However,

3条回答
  •  -上瘾入骨i
    2021-01-04 02:39

    Semantics, at both the machine and human level.

    Also, it keeps test code in line with the "exports" interface, e.g.,

    module.exports = {
      before: function(){
        // ...
      },
    
      'Array': {
        '#indexOf()': {
          'should return -1 when not present': function(){
            [1,2,3].indexOf(4).should.equal(-1);
          }
        }
      }
    };
    

提交回复
热议问题