1

const expect = require("chai").expect;

class Test 
{
 constructor(){ this.x= 10;}
 run() {
 describe("test goes here", function() {
  it("sample test", function() {
    expect(this.x).to.be.eq(10);
  });
 });
 }
}

new Test().run();

getting x is undefined.

Issue : this inside describe points to complete different context, how to make x available to this inside mocha test

user522170
  • 623
  • 1
  • 6
  • 21

1 Answers1

0

Use arrow functions () => this... or .bind on your functions.

describe("test goes here", () => {
  it("sample test", () => {
    expect(this.x).to.be.eq(10);
  });
 });
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445