title: How to test a method in Jasmine if the code in `beforeEach` is asynchronous?
body: <p>I'm trying to write some tests with Jasmine, but now have a problem if there are some code is asynchronous in <code>beforeEach</code>.</p>
  
  <p>The sample code looks like:</p>
  
  <pre><code>describe("Jasmine", function() {
  
      var data ;
  
      beforeEach(function(){
          console.log('Before each');
          getSomeDataFromRemote(function(res){
              data = res;
          });
      });
  
      it("test1", function() {
          expect(data).toBe(something);
          console.log('Test finished');
      });
  
  });
  </code></pre>
  
  <p>You can see, in the <code>beforeEach</code>, I want to get some data from remote, and assign it to the <code>data</code> asynchronously. </p>
  
  <p>But in the <code>test1</code>, when I try to verify:</p>
  
  <pre><code> expect(data).toBe(something);
  </code></pre>
  
  <p>The data is <code>undefined</code>, because <code>getSomeDataFromRemote</code> has not finished yet.</p>
  
  <p>How to fix it?</p>