jam-cloud/spec/javascripts/jamkazam.spec.js

52 lines
1.9 KiB
JavaScript

(function(context, $) {
describe("JamKazam Main Application", function() {
var jamkazam;
beforeEach(function() {
jamkazam = new context.JK.JamKazam();
});
describe("Event Subscription", function() {
it("Subscribing to ping should call function", function() {
var called = false;
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {
called = true;
});
var header = {type: context.JK.MessageType.PING_ACK};
var payload = {};
jamkazam.fireEvent(header, payload);
expect(called).toBeTruthy();
});
it("All subscribers should be called", function() {
var callCount = 0;
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {callCount += 1;});
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {callCount += 2;});
var header = {type: context.JK.MessageType.PING_ACK};
var payload = {};
jamkazam.fireEvent(header, payload);
expect(callCount).toEqual(3);
});
it("An error in a subscriber should be caught", function() {
var callCount = 0;
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {callCount += 1;});
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {throw "Intentional Error";});
jamkazam.subscribe(context.JK.MessageType.PING_ACK, function() {callCount += 1;});
var header = {type: context.JK.MessageType.PING_ACK};
var payload = {};
jamkazam.fireEvent(header, payload);
expect(callCount).toEqual(2);
});
});
});
}(window, jQuery));