title: Scoping in Jest when mocking functions
body: <p>I have a test where I'm trying to mock a component in two different situations. When I use <code>jest.fn</code>. It almost looks like the first test is just taking the value from the second.</p>
  
  <pre><code>describe('tests', () =&gt; {
    let sampleArray = new Array()
    Array.prototype.test = function() {
      return this.innerArray()
    }
    describe('empty', () =&gt; {
      sampleArray.innerArray = jest.fn(() =&gt; [])
      it('testArray is empty', () =&gt; {
        expect(sampleArray.test().length).toEqual(0)
      })
    })
  
    describe('not empty', () =&gt; {
      sampleArray.innerArray = jest.fn(() =&gt; ['test'])
      it('testArray is not empty', () =&gt; {
        console.log(sampleArray.innerArray())
        expect(sampleArray.test().length).toEqual(1)
      })
    })
  })
  </code></pre>
  
  <p>When I <code>console.log</code> I get the array I expect from innerArray, but it just looks like it doesn't use it.</p>
  
  <pre><code>FAIL  test/sample.test.js
    tests
      empty
        ✕ testArray is empty (8ms)
      not empty
        ✓ testArray is not empty (4ms)
  
    ● tests › empty › testArray is empty
  
      expect(received).toEqual(expected)
  
      Expected value to equal:
        0
      Received:
        1
  </code></pre>
  
  <p>edit: If I place it inside the <code>it</code> scope, it works. But why can't I do it in the <code>describe</code> scope?</p>
  
  <pre><code>describe('tests', () =&gt; {
    let sampleArray = new Array()
    Array.prototype.test = function() {
      return this.innerArray()
    }
    describe('empty', () =&gt; {
      it('testArray is empty', () =&gt; {
        sampleArray.innerArray = jest.fn(() =&gt; [])
        console.log(sampleArray.innerArray())
        expect(sampleArray.test().length).toEqual(0)
      })
    })
  
    describe('not empty', () =&gt; {
      it('testArray is not empty', () =&gt; {
        sampleArray.innerArray = jest.fn(() =&gt; ['test'])
        expect(sampleArray.test().length).toEqual(1)
      })
    })//works
  </code></pre>