摩卡测试中的上下文未定义

roz*_*zza 3 mocha.js node.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', () => {
     const testName = this.test.ctx.currentTest.fullTitle();
   });
});
Run Code Online (Sandbox Code Playgroud)

但“这个”是未定义的。我如何获得测试名称?

fil*_*a90 5

https://mochajs.org/#arrow-functions

\n\n

正如文档所说Passing arrow functions (\xe2\x80\x9clambdas\xe2\x80\x9d) to Mocha is discouraged\nfunction使用

\n\n
describe(\'test my scenarios dude\', function() {\n   before(\'do all my pre-test stuff\', function() {\n     const blah = blah;\n   });\n\n   it(\'tests my really useful test\', function() {\n     const testName = this.test.ctx.currentTest.fullTitle();\n   });\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

您还可以在此处阅读有关箭头函数的更多信息。他们没有this

\n