title: Jest passing variables to tests
body: <p>I have a variable that is needed by various test suites. Rather than initialising in every suite, I have decided to have one test file with a <code>beforeAll</code> which initialises the variable and split the tests in suite files, which basically export the tests.</p>
  <p>For the sake of simplicity let's assume that my test file (the only one <code>jest</code> calls) is like this:</p>
  <pre class="lang-js prettyprint-override"><code>import { foobar } from './foobar'
  
  let foo
  
  beforeAll(() =&gt; {
    foo = 'bar'
  })
  
  describe('foo is bar', () =&gt; {
    foobar(foo)
  })
  </code></pre>
  <p>and one of my test suite file is like this:</p>
  <pre class="lang-js prettyprint-override"><code>export const foobar = (foo) =&gt; {
    it('should be defined', () =&gt; expect(foo).toBeDefined())
    it('should be bar', () =&gt; expect(foo).toMatch('bar'))
  }
  </code></pre>
  <p>It does not work. <code>foo</code> is always <code>undefined</code> and the tests fail.</p>
  <pre class="lang-sh prettyprint-override"><code>foo is bar
      ✕ should be defined (3 ms)
      ✕ should be bar
  </code></pre>
  <p>What am I missing? I might be having a brain fart day, so excuse me if I am being silly.</p>
  <p>Edit (@Estus Flask)</p>
  <p>If I define only the check in the imported <code>foobar</code> file like so:</p>
  <pre class="lang-js prettyprint-override"><code>export const foobar = (foo) =&gt; expect(foo).toBeDefined()
  </code></pre>
  <p>and I modify the test file like so:</p>
  <pre class="lang-js prettyprint-override"><code>import { foobar } from './foobar'
  
  let foo
  
  beforeAll(() =&gt; {
    foo = 'bar'
  })
  
  describe('foo is bar', () =&gt; {
    it('should be defined', () =&gt; foobar(foo))
  })
  </code></pre>
  <p>It works:</p>
  <pre class="lang-sh prettyprint-override"><code>foo is bar
    ✓ should be defined (2 ms)
  </code></pre>
  <p>So, how is Jest organising the different processes? And also yes, I could put the parameter in the global namespace, but I would like to avoid doing so.</p>