Created
December 19, 2010 04:44
-
-
Save Pablosan/747110 to your computer and use it in GitHub Desktop.
Simple function to demonstrate getting test coverage around Javascript code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resetForm() { | |
document.getElementById("searchValue").disabled=true; | |
document.getElementById("filterValue").disabled=true; | |
document.someComplexForm.reset(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Reset Form to Default Values', function() { | |
it('returns the form to the way it was when first loaded', function() { | |
addTagToHtmlBody('<div id="searchValue"></div>'); | |
addTagToHtmlBody('<div id="filterValue"></div>'); | |
document.someComplexForm = new MockComplexForm(); | |
spyOn(document.someComplexForm, 'reset'); | |
resetForm(); | |
expect(document.getElementById("searchValue").disabled).toBeTruthy(); | |
expect(document.getElementById("filterValue").disabled).toBeTruthy(); | |
expect(document.someComplexForm.reset).toHaveBeenCalled(); | |
function addTagToHtmlBody(new_tag) { | |
$(new_tag).appendTo('body'); | |
} | |
function MockComplexForm() { | |
this.reset = function() { /* Does something interesting that is tested elsewhere */ } | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment