想要在mocha testfunction中添加额外的上下文,但是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
});
});
});正如大家所看到的,一个非常简单的index.js,实际上生成了一个测试报告。但每6个addContext中就有4个缺失。希望有人知道答案??
发布于 2022-02-16 01:10:20
看起来您需要将done作为参数添加到it块中,然后在关闭的it块之前调用done();。
下面是官方的mochawesome npm包GitHub repo的示例代码片段:
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();
});
}这是我的代码来源:
https://github.com/adamgruber/mochawesome/blob/master/test-functional/test-context.js
让我知道这是否有效。
https://stackoverflow.com/questions/54422017
复制相似问题