如何在类中编写摩卡测试

问题描述 投票:0回答:1

是否有可能在类e里面编写摩卡测试:

 class test
 {

   // mocha test
   describe("test goes here", function(){
   it("sample test", function(){})
   })
 }

在这种情况下如何触发测试?

javascript mocha chai
1个回答
1
投票

必须为mocha同步定义测试,才能收集您的测试。

index.test.js

const expect = require("chai").expect;

class Test {
  run() {
    describe("test goes here", function() {
      it("sample test", function() {
        expect(1 + 1).to.be.eq(2);
      });
    });
  }
}

new Test().run();

测试结果:

  test goes here
    ✓ sample test


  1 passing (5ms)

---------------|----------|----------|----------|----------|-------------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files      |      100 |      100 |      100 |      100 |                   |
 index.test.js |      100 |      100 |      100 |      100 |                   |
---------------|----------|----------|----------|----------|-------------------|

源代码:https://github.com/mrdulin/mocha-chai-sinon-codelab/tree/master/src/stackoverflow/59984203

© www.soinside.com 2019 - 2024. All rights reserved.