Created
November 19, 2011 15:15
-
-
Save chrisjpowers/1378942 to your computer and use it in GitHub Desktop.
Example of tangled code for refactoring
This file contains 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("pressing the done button", function() { | |
var container, input, button, welcome; | |
beforeEach(function() { | |
container = $("div"); | |
input = $("<input>", {"class": "name"}); | |
button = $("<button>", {"class": "done"}); | |
welcome = $("<div>", {"id": "welcome"}); | |
container.append(input, button, welcome); | |
$("body").append(container); | |
}); | |
afterEach(function() { | |
container.remove(); | |
}); | |
it("displays welcome with first name from input", function() { | |
input.val("Dr. John Doe"); | |
button.click(); | |
expect(welcome.text()).toEqual("Welcome, John!"); | |
}); | |
}); |
This file contains 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
$("button.done").live("click", function() { | |
var name = $("input.name").val(); | |
name = name.split(" "); | |
if(name[0] == "Mr." || | |
name[0] == "Mrs." || | |
name[0] == "Dr.") { | |
name.shift(); | |
} | |
$("#welcome").text("Welcome, " + name[0] + "!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment