Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
should populate inputs with invalid field types (part of Capybara tes…
Browse files Browse the repository at this point in the history
…t suite)
  • Loading branch information
boblail authored and assaf committed Jan 9, 2011
1 parent d23ab4b commit 1988aec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion spec/forms-spec.coffee
Expand Up @@ -11,6 +11,7 @@ brains.get "/form", (req, res)-> res.send """
<input type="text" name="email" id="field-email"></label>
<textarea name="likes" id="field-likes">Warm brains</textarea>
<input type="password" name="password" id="field-password">
<input type="badtype" name="invalidtype" id="field-invalidtype" />
<label>Hungry</label>
<label>You bet<input type="checkbox" name="hungry[]" value="you bet" id="field-hungry"></label>
Expand Down Expand Up @@ -106,7 +107,7 @@ vows.describe("Forms").addBatch(
"fill field":
zombie.wants "http://localhost:3003/form"
topic: (browser)->
for field in ["email", "likes", "name", "password"]
for field in ["email", "likes", "name", "password", "invalidtype"]
do (field)->
browser.querySelector("#field-#{field}").addEventListener "change", -> browser["#{field}Changed"] = true
@callback null, browser
Expand All @@ -130,6 +131,11 @@ vows.describe("Forms").addBatch(
browser.fill ":password[name=password]", "b100d"
"should set password": (browser)-> assert.equal browser.querySelector("#field-password").value, "b100d"
"should fire change event": (browser)-> assert.ok browser.passwordChanged
"input without a valid type":
topic: (browser)->
browser.fill ":input[name=invalidtype]", "some value"
"should set value": (browser)-> assert.equal browser.querySelector("#field-invalidtype").value, "some value"
"should fire change event": (browser)-> assert.ok browser.invalidtypeChanged

"check box":
zombie.wants "http://localhost:3003/form"
Expand Down
2 changes: 1 addition & 1 deletion src/zombie/browser.coffee
Expand Up @@ -324,7 +324,7 @@ class Browser extends require("events").EventEmitter
# Returns this
this.fill = (selector, value)->
field = @field(selector)
if field && (field.tagName == "TEXTAREA" || (field.tagName == "INPUT" && TEXT_TYPES.indexOf(field.type) >= 0))
if field && (field.tagName == "TEXTAREA" || (field.tagName == "INPUT")) # && TEXT_TYPES.indexOf(field.type) >= 0))
throw new Error("This INPUT field is disabled") if field.getAttribute("input")
throw new Error("This INPUT field is readonly") if field.getAttribute("readonly")
field.value = value
Expand Down

0 comments on commit 1988aec

Please sign in to comment.