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

57 lines
2.1 KiB
JavaScript

(function(context, $) {
describe("JamKazam Main Application", function() {
var jamkazam;
beforeEach(function() {
jasmine.getFixtures().fixturesPath = '/spec/javascripts/fixtures';
var opts = {
layoutOpts: {
allowBodyOverflow: true
}
};
jamkazam = new context.JK.JamKazam(opts);
});
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));