0

At the moment, I am using a var that is assigned an object from another hook. I am wanting to change this to a let, but I keep stumbling across errors.

Current setup:

var tc;

module.exports = {

  before(browser) {
    tc = new func()(x, y); // needs to be assigned here.
  },

  'Test': function (browser) {
    tc // needs to be referenced here too.
  },

};

How can I change it to let yet assign/reference it within other hooks and test cases (I'm using Mocha).

1 Answers1

0

Use this.parameter

module.exports = {

  before(browser) {
    this.tc = new func()(x, y); // Now it's assigned to the object context.
  },

  'Test': function (browser) {
    return this.tc; // You can reference to the variable inside the object
  },

};
Artur Nista
  • 359
  • 1
  • 4
  • Thank you for your reply. How can I reference a parameter inside the `tc` object within the `test` function? –  Nov 10 '16 at 15:38
  • Do you say something like this? `test: function() { return this.tc.param; }` – Artur Nista Nov 10 '16 at 16:43
  • Kind of. Within the 'test', I would like to pass a parameter from the `tc` object to another function. Like so: `browser.page.function(tc.parameter, tc.anotherParameter);` –  Nov 11 '16 at 11:19
  • `browser.page.function(this.tc.parameter, this.tc.anotherParameter);`, like this? – Artur Nista Nov 11 '16 at 18:25