title: Mouse Events in Jasmine
body: <p>I'm new to Jasmine and jQuery and am having trouble spying on a mousedown event. Here's the part of my spec that's failing (Jasmine says that that the spy mousedown hasn't been called.) I suspect that it may be because of the way that I trigger the event.</p>
  
  <pre><code>it("draws a path on mousedown", function() {
    spyOn(drawing,'mousedown');
    $('#canvas').trigger('mousedown');
    expect(drawing.mousedown).toHaveBeenCalled();
    expect(drawing.isDrawing).toEqual(true);
  });
  </code></pre>
  
  <p>The corresponding Javascript code is here:</p>
  
  <pre><code>function Drawing(canvas, eraseAllButton, eraseButton) {
    this.isDrawing = false;
    this.erasing = false;
    this.canvas = canvas;
    this.context = canvas.getContext("2d");
    this.eraseAllButton = eraseAllButton;
    this.eraseButton = eraseButton;
  
  // Sets up event listeners for drawing.
    var self = this;
    this.canvas.addEventListener("mousedown", function () { self.mousedown() }, false);
  };
  
  // Begins to draw a path on mousedown.
  Drawing.prototype.mousedown = function(e) { 
    if (!e) var e = window.event;
    e.preventDefault();       
  
    this.isDrawing = true;
    this.x = e.pageX - this.canvas.offsetLeft;
    this.y = e.pageY - this.canvas.offsetTop;
    this.context.beginPath();
    this.context.moveTo(this.x, this.y);
  };
  </code></pre>