Node.js 摩卡测试中的上下文未定义
所以我使用mocha和node来测试一些API。我有一个测试Node.js 摩卡测试中的上下文未定义,node.js,mocha.js,Node.js,Mocha.js,所以我使用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', ()
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”是未定义的。如何获取测试名称?
正如文档所说,不鼓励将箭头功能(“lambdas”)传递给摩卡
改用功能
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();
});
});
您还可以阅读有关箭头函数的更多信息。他们没有这个