Skip to content

Instantly share code, notes, and snippets.

@mdowning
Created February 28, 2011 22:53
Show Gist options
  • Save mdowning/848218 to your computer and use it in GitHub Desktop.
Save mdowning/848218 to your computer and use it in GitHub Desktop.
describe("Page Behaviors", function () {
beforeEach(function() {
spyOn(window, "alert").andCallFake(function() {
});
});
describe("given a page behavior", function () {
beforeEach(function() {
BehaviorMap['.foo'] = function() {
alert("The Pentagon!");
};
BehaviorMap['.bar'] = function() {
alert('Your Mom')
};
});
it("executes the behavior when the associate selector is present", function() {
SpecDOM().append('<div class="foo"></div>');
Behaviors.addBehaviors();
expect(window.alert).toHaveBeenCalledWith("The Pentagon!");
});
it("does not execute the behavior when the selector is not present", function() {
Behaviors.addBehaviors();
expect(window.alert).not.toHaveBeenCalled();
});
it("doesn't execute any other behaviors", function() {
expect(window.alert).not.toHaveBeenCalledWith('Your Mom');
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment