Commit 3cadee4c authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Fixed jasmine tests to work with event emitter.

parent ea87e722
......@@ -6,8 +6,8 @@
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.4.1/jasmine.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/bootstrap-theme.min.css">
<script src="lib/jasmine-2.4.1/jasmine.js"></script>
<script src="lib/jasmine-2.4.1/jasmine-html.js"></script>
......
......@@ -61,7 +61,7 @@ describe("Bootstrap Tabs", function () {
it("should call user 'show tab' handlers", function () {
var showHandlerSpy = jasmine.createSpy('showhandler');
bsTabs.addTabShowHandler(showHandlerSpy);
bsTabs.on('bootstrap.tab.shown', showHandlerSpy);
bsTabs.activateTab('tab1');
expect(showHandlerSpy).toHaveBeenCalled();
......
......@@ -45,23 +45,28 @@ describe("Form", function () {
it("should notify upon form change", function () {
var changeHandler = jasmine.createSpy('ChangeHandler');
form.addChangeHandler(changeHandler);
form.on('form.changed', changeHandler);
$("#name").change();
expect(changeHandler).toHaveBeenCalledTimes(1);
expect(changeHandler).toHaveBeenCalledWith(form);
var callArgs = changeHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBeDefined();
expect(callArgs.target).toBe(form);
});
it("should notify upon state reset", function () {
var resetHandler = jasmine.createSpy('StateResetHandler');
form.addResetHandler(resetHandler);
form.on('form.reset', resetHandler);
form.resetFormChanged();
expect(resetHandler).toHaveBeenCalledTimes(1);
expect(resetHandler).toHaveBeenCalledWith(form);
var callArgs = resetHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBeDefined();
expect(callArgs.target).toBe(form);
});
it("should reset state upon resetFormChanged()", function () {
......@@ -79,8 +84,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler);
form.addSubmitFailureHandler(failureHandler);
form.on('form.submit.successful', successHandler);
form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({
......@@ -89,7 +94,7 @@ describe("Form", function () {
"responseText": "{ \"status\": \"success\" }"
});
expect(successHandler).toHaveBeenCalledWith(form, {status: "success"}, "success");
expect(successHandler).toHaveBeenCalledTimes(1);
expect(failureHandler).not.toHaveBeenCalled();
jasmine.Ajax.uninstall();
......@@ -101,8 +106,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler);
form.addSubmitFailureHandler(failureHandler);
form.on('form.submit.successful', successHandler);
form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({
......@@ -114,10 +119,12 @@ describe("Form", function () {
expect(successHandler).not.toHaveBeenCalled();
expect(failureHandler).toHaveBeenCalled();
expect(failureHandler.calls.argsFor(0)[0]).toBe(form);
expect(failureHandler.calls.argsFor(0)[1]).toBe("error");
// arg 2 is jqXHR, which I don't want to test for, and therefore continue with 3
expect(failureHandler.calls.argsFor(0)[3]).toBe("not found");
var callArgs = failureHandler.calls.argsFor(0)[0];
expect(callArgs.target).toBe(form);
expect(callArgs.textStatus).toBe("error");
expect(callArgs.errorThrown).toBe("not found");
jasmine.Ajax.uninstall();
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment