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

Commit

Permalink
Fix null error from resource when request has no response.
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Feb 22, 2011
1 parent ba43510 commit fa9041b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions spec/script-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ brains.get "/script/window", (req, res)-> res.send "<script>document.title = [wi

brains.get "/script/incomplete", (req, res)-> res.send "<script>1 +</script>"

brains.get "/script/split", (req, res)-> res.send "<script>foo = foo ? 1 : 2; '&'; document.title = foo</script>"

brains.get "/script/error", (req, res)-> res.send "<script>foo.bar</script>"

brains.get "/script/order", (req, res)-> res.send """
Expand Down Expand Up @@ -156,6 +158,12 @@ vows.describe("Scripts").addBatch(
zombie.wants "http://localhost:3003/script/order"
"should run scripts in order regardless of source": (browser)-> assert.equal browser.text("title"), "ZeroOneTwo"

###
"split script":
zombie.wants "http://localhost:3003/script/split"
"should run full script": (browser)-> assert.equal browser.text("title"), "1"
###

"using eval":
zombie.wants "http://localhost:3003/script/eval"
"should evaluate in global scope": (browser)-> assert.equal browser.document.title, "3"
Expand Down
6 changes: 3 additions & 3 deletions src/zombie/browser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,17 @@ class Browser extends require("events").EventEmitter
#
# Returns the status code of the request for loading the window.
@__defineGetter__ "statusCode", ->
@window.resources.first?.response.statusCode
@window.resources.first?.response?.statusCode
# ### browser.redirected => Boolean
#
# Returns true if the request for loading the window followed a
# redirect.
@__defineGetter__ "redirected", ->
@window.resources.first?.response.redirected
@window.resources.first?.response?.redirected
# ### source => String
#
# Returns the unmodified source of the document loaded by the browser
@__defineGetter__ "source", => @window.resources.first?.response.body
@__defineGetter__ "source", => @window.resources.first?.response?.body

# ### browser.cache => Cache
#
Expand Down

0 comments on commit fa9041b

Please sign in to comment.