Skip to content

Commit

Permalink
Allow browser.select to use the option text.
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed May 28, 2012
1 parent dd7ddc7 commit 5c44585
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ zombie.js-changelog(7) -- Changelog

Set `accept-encoding` to "identity".

Allow `browser.select` to use the option text.


## Version 1.1.7 2012-05-27

Expand Down
3 changes: 3 additions & 0 deletions lib/zombie/browser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ class Browser extends EventEmitter
for option in field.options
if option.label == value
return option
for option in field.options
if option.textContent.trim() == value
return option
throw new Error("No OPTION '#{value}'")

# ### browser.select(selector, value, callback) => this
Expand Down
19 changes: 19 additions & 0 deletions test/forms_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ describe "Forms", ->
<option id="hobbies-messy">Make Messy</option>
<option>Sleep</option>
</select>
<select name="months" id="field-months">
<option value=""></option>
<option value="jan_2011"> Jan 2011 </option>
<option value="feb_2011"> Feb 2011 </option>
<option value="mar_2011"> Mar 2011 </option>
</select>
<input type="unknown" name="unknown" value="yes">
<input type="reset" value="Reset">
Expand Down Expand Up @@ -477,6 +484,18 @@ describe "Forms", ->
it "should fire change event", ->
assert @browser.stateChanged

describe "select name using option text", ->
before ->
@browser.select "months", "Jan 2011"

it "should set value", ->
assert.equal @browser.querySelector("#field-months").value, "jan_2011"
it "should select second option", ->
selected = (!!option.getAttribute("selected") for option in @browser.querySelector("#field-months").options)
assert.deepEqual selected, [false, true, false, false]
it "should fire change event", ->
assert @browser.stateChanged

describe "select option value directly", ->
before ->
@browser.selectOption @browser.querySelector("#option-killed-thousands")
Expand Down

0 comments on commit 5c44585

Please sign in to comment.