title: How to access class properties of Jest Test Environment inside child test?
body: <p>I have created a testing environment for jest. It's based very closely to <a href="https://jestjs.io/docs/en/configuration#testenvironment-string" rel="nofollow noreferrer">their official docs</a>.</p>
  
  <p>I am setting a few values in the constructor that I would like to make available to the tests that are used within the environment. (See <code>this.foo = bar</code>).</p>
  
  <h3>Testing Env:</h3>
  
  <pre><code>// my-custom-environment
  const NodeEnvironment = require('jest-environment-node');
  
  class CustomEnvironment extends NodeEnvironment {
    constructor(config, context) {
      super(config, context);
      this.testPath = context.testPath;
      this.foo = 'bar'; // Trying to access
    }
  
    async setup() {
      await super.setup();
      await someSetupTasks(this.testPath);
      this.global.someGlobalObject = createGlobalObject();
    }
  
    async teardown() {
      this.global.someGlobalObject = destroyGlobalObject();
      await someTeardownTasks();
      await super.teardown();
    }
  
    runScript(script) {
      return super.runScript(script);
    }
  }
  
  module.exports = CustomEnvironment;
  </code></pre>
  
  <p>I run my tests using the equivalent of: </p>
  
  <pre><code>jest --env ./tests/&lt;testing-env&gt;.js
  </code></pre>
  
  <p>Where do I access <code>this.foo</code> within my tests that are tested within this testing environment?</p>
  
  <pre><code>describe('Sample Test', () =&gt; {
    it('this.foo = bar', () =&gt; {
      expect(this.foo).toBe('bar');
    });
  });
  </code></pre>
  
  <p>I tried replacing both arrow functions with es5 function formats (hoping that <code>this</code> would be in scope) and didn't have any luck. </p>
  
  <p>How can I get class properties from my testing environment from within my tests in that environment?</p>