0

我是摩卡的新手。我想将测试用例 2 从 a.js 文件调用到 b.js,就像导入测试用例一样,因为在 b.js 文件中可以重复相同的测试用例。例子

File a.js :
describe('Sample a',function(){
        it('Test case1',function(done){
          console.log('Testing test case1');
        });
     it('Test case2',function(done){
        console.log('Testing test case2');
     });
     it('Test case3',function(done){
        console.log('Testing test case3');
     });
  });

File b.js:
describe('Sample b',function(){
     it('Test case2',function(done){
     console.log('Testing test case2');
      });
 });

请提供此问题的解决方案。

谢谢

4

1 回答 1

1

There's no facility in Mocha to allow one test (it) to invoke another test or to allow a suite (describe) to invoke a test in another suite.

When you have tests that share logic, the solution is the same as any other two pieces of JavaScript code that share logic: refactor the code so that the shared logic is moved to a function that can be called, and call it from the code that needs it. Since your tests are in different files, you are going to have to import the shared code in your test files. You can use a loader like RequireJS or SystemJS to load the code at runtime, or use a bundler like Webpack or Browserify to pack your modules into a single bundle.

于 2017-03-14T10:37:23.413 回答