title: How do I write a jasmine test for a method that contains a global variable from another class/file?
body: <p>My tests fails for the following reason:</p>
  
  <blockquote>
    <p>ReferenceError: Can't find variable: moving_canvas_context in file
    (line 5)</p>
  </blockquote>
  
  <p>I understand the reason the test is failing. It doesn't understand the variable since it is defined in a separate JavaScript file. However, it is declared globally and works in reality.</p>
  
  <p>How do I write a jasmine test for this <code>clear_canvas</code> function?</p>
  
  <p>JavaScript <code>Canvas_Actions</code>:</p>
  
  <pre><code>(function() {
    window.Canvas_Actions = (function() {
      function Canvas_Actions() {}
      Canvas_Actions.prototype.clear_canvas = function() {
        moving_canvas_context.clearRect(0, 0, moving_canvas.width, moving_canvas.height);
        main_canvas_context.drawImage(window.background_image, 0, 0, main_canvas.width, main_canvas.height);
        return window.canvas_objects = [];
      };
      return Canvas_Actions;
    })();
  }).call(this);
  </code></pre>
  
  <p>Jasmine Test for <code>Canvas_Actions</code>:</p>
  
  <pre><code>(function() {
    describe('Canvas Actions', function() {
      return describe('clear_canvas', function() {
        return it('clears the canvases and deletes all objects', function() {
          var actions;
          jasmine.getFixtures().fixturesPath = "../spec/javascript/fixtures";
          loadFixtures("canvas_fixture.html");
          actions = new Canvas_Actions();
          actions.clear_canvas();
          return expect(canvas_objects).toEqual([]);
        });
      });
    });
  }).call(this);
  </code></pre>