How to get Mocha's test name before?

I am trying to get the current name describeinside the hook before, for example:

describe('increasing 3 times', function() {

  before(function() {
    console.log('test name');
  });

  ...

});

I basically want to get the string “3x magnification” at the beginning.

How can I do that?

Thank!

+4
source share
1 answer

Here is the code that illustrates how you can do this:

describe("top", function () {
    before(function () {
        console.log("full title:", this.test.fullTitle());
        console.log("parent title:", this.test.parent.title);
    });

    it("test 1", function () {});
});

Run with the reporter spec, this will output:

full title: top "before all" hook
parent title: top
     test 1 


  1 passing (4ms)

Mocha , (describe, before, it ..), this Context. test. , , . before Hook, before. fullTitle() : , (describe), . Hook parent, , . title, , describe.

+4

Source: https://habr.com/ru/post/1568201/


All Articles