diff --git a/CHANGELOG.md b/CHANGELOG.md index c054bb55a..f942f1dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ Added debugging to help you figure out what's happening when tests run: - Call `browser.debug` with a function to print the result of that function call. +Testing that Zombie.js can handle jQuery live form submit event. Yes it +can! + + 185 Tests + 1.8 sec to complete + ## Version 0.7.2 2010-12-27 diff --git a/package.json b/package.json index 5b7db98ce..87912d9e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zombie", - "version": "0.7.2", + "version": "0.7.3", "description": "Insanely fast, full-stack, headless testing using node.js", "homepage": "http://zombie.labnotes.org/", "author": "Assaf Arkin (http://labnotes.org/)", diff --git a/spec/browser-spec.coffee b/spec/browser-spec.coffee index 9fead9639..6a8cd4ce0 100644 --- a/spec/browser-spec.coffee +++ b/spec/browser-spec.coffee @@ -25,15 +25,14 @@ brains.get "/living", (req, res)-> res.send """ -
- Kill -
- - - - - -
+
+ Kill +
+ + + +
+
Walking Aimlessly
@@ -41,11 +40,14 @@ brains.get "/living", (req, res)-> res.send """ brains.get "/app.js", (req, res)-> res.send """ Sammy("#main", function(app) { app.get("#/", function(context) { - context.swap("The Living"); + document.title = "The Living"; }); app.get("#/dead", function(context) { context.swap("The Living Dead"); }); + app.post("#/dead", function(context) { + document.title = "Signed up"; + }); }); $(function() { Sammy("#main").run("#/") }); """ @@ -76,7 +78,7 @@ vows.describe("Browser").addBatch( "run app": zombie.wants "http://localhost:3003/living" - "should execute route": (browser)-> assert.equal browser.text("#main"), "The Living" + "should execute route": (browser)-> assert.equal browser.document.title, "The Living" "should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/" "move around": topic: (browser)-> @@ -115,13 +117,13 @@ vows.describe("Browser").addBatch( "should query from document": (browser)-> assert.equal browser.text(".now"), "Walking Aimlessly" "should query from context": (browser)-> assert.equal browser.text(".now", browser.body), "Walking Aimlessly" "should query from context": (browser)-> assert.equal browser.text(".now", browser.querySelector("#main")), "" - "should combine multiple elements": (browser)-> assert.equal browser.text("form label"), "Name Email" + "should combine multiple elements": (browser)-> assert.equal browser.text("form label"), "Email Password " "query html": topic: (browser)-> browser "should query from document": (browser)-> assert.equal browser.html(".now"), "
Walking Aimlessly
" "should query from context": (browser)-> assert.equal browser.html(".now", browser.body), "Walking Aimlessly" "should query from context": (browser)-> assert.equal browser.html(".now", browser.querySelector("#main")), "" - "should combine multiple elements": (browser)-> assert.equal browser.html("#main, a"), "
The Living
Kill" + "should combine multiple elements": (browser)-> assert.equal browser.html("title, #main a"), "The LivingKill" "click link": zombie.wants "http://localhost:3003/living" @@ -130,4 +132,12 @@ vows.describe("Browser").addBatch( "should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/dead" "should run all events": (browser)-> assert.equal browser.document.title, "The Dead" + "live events": + zombie.wants "http://localhost:3003/living" + topic: (browser)-> + browser.fill("Email", "armbiter@zombies").fill("Password", "br41nz"). + pressButton "Sign Me Up", @callback + "should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/" + "should process event": (browser)-> assert.equal browser.document.title, "Signed up" + ).export(module) diff --git a/src/zombie/forms.coffee b/src/zombie/forms.coffee index 5437bbf83..2982e9f12 100644 --- a/src/zombie/forms.coffee +++ b/src/zombie/forms.coffee @@ -48,6 +48,13 @@ core.HTMLFormElement.prototype._eventDefault = (event)-> # Buttons # ------- +# Default type for buttons is submit. +core.Document.prototype._elementBuilders["button"] = (doc, s)-> + button = new core.HTMLButtonElement(doc, s) + button.type ||= "submit" + return button + + # Default behavior for clicking on reset/submit buttons. core.HTMLInputElement.prototype._eventDefault = (event)-> return if @getAttribute("disabled") diff --git a/src/zombie/history.coffee b/src/zombie/history.coffee index c3b3a894d..90d1e6925 100644 --- a/src/zombie/history.coffee +++ b/src/zombie/history.coffee @@ -43,7 +43,9 @@ class History # Make a request to external resource. We use this to fetch pages and # submit forms, see _loadPage and _submit. - resource = (url, method = "GET", data, enctype)=> + resource = (url, method, data, enctype)=> + method = (method || "GET").toUpperCase() + browser.debug "#{method} #{URL.format(url)}" throw new Error("Cannot load resource: #{URL.format(url)}") unless url.protocol && url.hostname window = browser.window window = browser.open() if browser.window.document