所以我使用mocha和node来测试一些api。我有一个测试
import { describe, before, it, xit } from 'mocha';
describe('test my scenarios dude', () => {
before('do all my pre-test stuff', () => {
const blah = blah;
});
it('tests my really useful test', () => {
const testName = this.test.ctx.currentTest.fullTitle();
});
});
但是'this'是未定义的。我怎样才能获得测试名称?
答案 0 :(得分:1)
https://mochajs.org/#arrow-functions
正如文档所说Passing arrow functions (“lambdas”) to Mocha is discouraged
使用function
代替
describe('test my scenarios dude', function() {
before('do all my pre-test stuff', function() {
const blah = blah;
});
it('tests my really useful test', function() {
const testName = this.test.ctx.currentTest.fullTitle();
});
});
您还可以阅读有关箭头功能here的更多信息。他们没有this