Permalink
Browse files

Fix firing the `change` event on SELECT tags when using jQuery.

  • Loading branch information...
1 parent 719fd7d commit 42f9eddd171b57d4455c66ab30151b1fc5eab44c @djanowski djanowski committed Jan 28, 2011
Showing with 44 additions and 0 deletions.
  1. +42 −0 spec/js-libs-compat.coffee
  2. +2 −0 src/zombie/browser.coffee
@@ -0,0 +1,42 @@
+require "./helpers"
+{ vows: vows, assert: assert, zombie: zombie, brains: brains } = require("vows")
+jsdom = require("jsdom")
+
+brains.get "/jquery", (req, res)-> res.send """
+ <html>
+ <head>
+ <title>jQuery</title>
+ <script src="/jquery.js"></script>
+ </head>
+ <body>
+ <select>
+ <option>None</option>
+ <option value="1">One</option>
+ </select>
+
+ <span id="option"></span>
+ </body>
+
+ <script>
+ $(function() {
+
+ $("select").bind("change", function() {
+ $("#option").text(this.value);
+ });
+
+ });
+ </script>
+ </html>
+ """
+
+vows.describe("Compatibility with JavaScript libraries").addBatch(
+ "jQuery":
+ zombie.wants "http://localhost:3003/jquery"
+ "selecting an option in a select element":
+ topic: (browser)->
+ browser.select "select", "1"
+ @callback null, browser
+ "should fire the change event": (browser)-> assert.equal browser.text("#option"), "1"
+
+
+).export(module)
@@ -491,7 +491,9 @@ class Browser extends require("events").EventEmitter
this.selectOption = (option)->
if(option && !option.selected)
select = @xpath("./ancestor::select", option).value[0]
+ @fire "beforeactivate", select
option.selected = true
+ @fire "beforedeactivate", select
@fire "change", select
return this

0 comments on commit 42f9edd

Please sign in to comment.