Mocha.Testfunction 中的 [mochawesome] addContext 问题

Jer*_*mer 5 javascript mocha.js selenium-webdriver

想在 mocha 测试函数中添加额外的上下文,但 addContext 不起作用。

describe('Test', function () {
    before('before', function () {
        addContext(this, 'context before all'); <-- Not working
      }); 
    after('after', function () {
        addContext(this, 'context after all'); <-- Not working
      }); 


it('Call just a working test API', function () {

    var test=this;
    addContext(this, 'Hello1 (this) !!!!');            <-- Working
    addContext(test, 'Hello2 (test) !!!!');            <-- Working
    unirest.post('http://mockbin.com/request')
    .headers({'Accept': 'application/json', 'Content-Type': 
    'application/json'})
    .send({ "parameter": 23, "foo": "bar" }).end(function (response) {
        console.log('In reponse function');
        addContext(test, 'Hello3 !!!!');            <-- Not working
        addContext(test, '' + response.body);       <-- Not working
    });
});
});
Run Code Online (Sandbox Code Playgroud)

如您所见,生成了一个非常简单的 index.js,并且确实生成了一个测试报告。但是 6 个 addContext 中有 4 个丢失了。希望有人知道答案??

ris*_*979 0

看起来您需要done在块内添加作为参数it,然后done();在关闭it块之前调用。

以下是来自官方mochawesome npm 包 GitHub 存储库的示例代码片段:

describe('Test Suite with Context', () => {
    it('should have text context', function (done) {
      (1 + 1).should.equal(2);
      addContext(this, 'this is the test context');
      done();
    });
}
Run Code Online (Sandbox Code Playgroud)

这是我获取代码的地方: https:
//github.com/adamgruber/mochawesome/blob/master/test-function/test-context.js

让我知道这个是否奏效。