Skip to content

Instantly share code, notes, and snippets.

@Pablosan
Created December 19, 2010 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pablosan/747110 to your computer and use it in GitHub Desktop.
Save Pablosan/747110 to your computer and use it in GitHub Desktop.
Simple function to demonstrate getting test coverage around Javascript code.
function resetForm() {
document.getElementById("searchValue").disabled=true;
document.getElementById("filterValue").disabled=true;
document.someComplexForm.reset();
}
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