title: Jasmine JS understanding global context
body: <p>I have a question about how Jasmine actually processes global context. In the api docs methods like <code>beforeEach(),afterEach(), etc</code> are described as global. Therefore, they are called without the <code>.</code> operator as Jasmine recognizes them. </p>
  
  <p>I have the following simple class: </p>
  
  <pre><code>export class VoteComponent { 
    totalVotes = 0; 
  
    upVote() { 
      this.totalVotes++;
    }
  
    downVote() { 
      this.totalVotes--;
    }
  }
  </code></pre>
  
  <p>And to test the following spec, which works fine:</p>
  
  <pre><code>import { VoteComponent } from './vote.component';
  
  describe('VoteComponent', () =&gt; {
    let Votes :VoteComponent;
   beforeEach(()=&gt;{
         Votes = new VoteComponent();
   })
    it('Upvotes', () =&gt; {
          Votes.upVote();
          expect(Votes.totalVotes).toBe(1);
    });
  
    it('Downvotes', () =&gt; {
          Votes.downVote();
          expect(Votes.totalVotes).toBe(-1);
    });
  });
  </code></pre>
  
  <p>However, if I change my spec to look like this:</p>
  
  <pre><code> // let Votes :VoteComponent;
   beforeEach(()=&gt;{
         let Votes = new VoteComponent();
   })
  </code></pre>
  
  <p>I get the following error: </p>
  
  <blockquote>
    <p>Chrome 67.0.3396 (Windows 10.0.0) VoteComponent Upvotes FAILED
            ReferenceError: Votes is not defined</p>
  </blockquote>
  
  <p>I don't get why this is. beforeEach() is a global context function, and gets called before each spec. But even so within the spec <code>Votes</code> is not recognized unless instantiated outside of the beforeEach().</p>
  
  <p>Why is this? I am using Angular-6, Karma 1.7 and Jasmine 2.9</p>