pivotal/jasmine — Issue #200: How about async events testing?
Author: Alexey-Raspopov
Created: 2012-03-09 22:25:23+00:00
State: open

Hi guys!
I'm newbie in using Jasmine and I have some trouble with async tests.
For example I have a constructor, which has link to some HTML element. And when I click on this element I want to execute some method of this constructor.

function MyConstrustor(element) {
this.element = element;
this.element.addEventListener('mousedown', this, false);
this.element.addEventListener('mousemove', this, false);
this.element.addEventListener('mouseup', this, false);
}
MyConstructor.prototype.handleEvent = function (event) {
switch (event.type) {
case 'mousedown':
this.mouseDown(event);
break;
case 'mousemove':
this.mouseMove(event);
break;
case 'mouseup':
this.mouseUp(event);
break;
}
};
MyConstructor.prototype.mouseDown = function (event) {
//some code goes here...
};
MyConstructor.prototype.mouseMove = function (event) {
//...and here
};
MyConstructor.prototype.mouseUp = function (event) {
//..and here
};

So, I want to spy some method in my object.
1. I create an element
2. I create an event
3. I create an object which should be instance of MyConstructor
4. I spyOn(myObject, 'someMethod')
5. I dispatch created event to element in my object

But, when I execute ```myObject.element.dispatchEvent(event)``` I have async code. Can anyone help me with this test? Thanks.