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 @@ ...@@ -6,8 +6,8 @@
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png"> <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="lib/jasmine-2.4.1/jasmine.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../packages/bootstrap/css/bootstrap-theme.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.js"></script>
<script src="lib/jasmine-2.4.1/jasmine-html.js"></script> <script src="lib/jasmine-2.4.1/jasmine-html.js"></script>
......
...@@ -61,7 +61,7 @@ describe("Bootstrap Tabs", function () { ...@@ -61,7 +61,7 @@ describe("Bootstrap Tabs", function () {
it("should call user 'show tab' handlers", function () { it("should call user 'show tab' handlers", function () {
var showHandlerSpy = jasmine.createSpy('showhandler'); var showHandlerSpy = jasmine.createSpy('showhandler');
bsTabs.addTabShowHandler(showHandlerSpy); bsTabs.on('bootstrap.tab.shown', showHandlerSpy);
bsTabs.activateTab('tab1'); bsTabs.activateTab('tab1');
expect(showHandlerSpy).toHaveBeenCalled(); expect(showHandlerSpy).toHaveBeenCalled();
......
...@@ -45,23 +45,28 @@ describe("Form", function () { ...@@ -45,23 +45,28 @@ describe("Form", function () {
it("should notify upon form change", function () { it("should notify upon form change", function () {
var changeHandler = jasmine.createSpy('ChangeHandler'); var changeHandler = jasmine.createSpy('ChangeHandler');
form.addChangeHandler(changeHandler); form.on('form.changed', changeHandler);
$("#name").change(); $("#name").change();
expect(changeHandler).toHaveBeenCalledTimes(1); 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 () { it("should notify upon state reset", function () {
var resetHandler = jasmine.createSpy('StateResetHandler'); var resetHandler = jasmine.createSpy('StateResetHandler');
form.addResetHandler(resetHandler); form.on('form.reset', resetHandler);
form.resetFormChanged(); form.resetFormChanged();
expect(resetHandler).toHaveBeenCalledTimes(1); 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 () { it("should reset state upon resetFormChanged()", function () {
...@@ -79,8 +84,8 @@ describe("Form", function () { ...@@ -79,8 +84,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success"); var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure"); var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler); form.on('form.submit.successful', successHandler);
form.addSubmitFailureHandler(failureHandler); form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url"); form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
...@@ -89,7 +94,7 @@ describe("Form", function () { ...@@ -89,7 +94,7 @@ describe("Form", function () {
"responseText": "{ \"status\": \"success\" }" "responseText": "{ \"status\": \"success\" }"
}); });
expect(successHandler).toHaveBeenCalledWith(form, {status: "success"}, "success"); expect(successHandler).toHaveBeenCalledTimes(1);
expect(failureHandler).not.toHaveBeenCalled(); expect(failureHandler).not.toHaveBeenCalled();
jasmine.Ajax.uninstall(); jasmine.Ajax.uninstall();
...@@ -101,8 +106,8 @@ describe("Form", function () { ...@@ -101,8 +106,8 @@ describe("Form", function () {
var successHandler = jasmine.createSpy("success"); var successHandler = jasmine.createSpy("success");
var failureHandler = jasmine.createSpy("failure"); var failureHandler = jasmine.createSpy("failure");
form.addSubmitSuccessHandler(successHandler); form.on('form.submit.successful', successHandler);
form.addSubmitFailureHandler(failureHandler); form.on('form.submit.failed', failureHandler);
form.submitTo("/test/url"); form.submitTo("/test/url");
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
...@@ -114,10 +119,12 @@ describe("Form", function () { ...@@ -114,10 +119,12 @@ describe("Form", function () {
expect(successHandler).not.toHaveBeenCalled(); expect(successHandler).not.toHaveBeenCalled();
expect(failureHandler).toHaveBeenCalled(); expect(failureHandler).toHaveBeenCalled();
expect(failureHandler.calls.argsFor(0)[0]).toBe(form);
expect(failureHandler.calls.argsFor(0)[1]).toBe("error"); var callArgs = failureHandler.calls.argsFor(0)[0];
// 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"); expect(callArgs.target).toBe(form);
expect(callArgs.textStatus).toBe("error");
expect(callArgs.errorThrown).toBe("not found");
jasmine.Ajax.uninstall(); 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