diff --git a/lib/browser.js b/lib/browser.js index 94cc38e..105f00e 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -15,7 +15,8 @@ var EventEmitter = require('events').EventEmitter , jsdom = require('jsdom') , jQuery = require('./jquery/core') , url = require('url') - , http = require('http'); + , http = require('http') + , qs = require('qs'); /** * Starting portno. @@ -157,6 +158,9 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){ // Request body if (options.body) { + if ('[object Object]' === Object.prototype.toString.call(options.body)) { + options.body = qs.stringify(options.body); + } headers['Content-Length'] = options.body.length; headers['Content-Type'] = headers['Content-Type'] || 'application/x-www-form-urlencoded'; } diff --git a/package.json b/package.json index 0d59b70..0bcf179 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "jsdom": ">= 0.1.21" , "htmlparser": ">= 1.7.3" , "should": ">= 0.0.4" - , "qs": ">= 0.1.0" + , "qs": ">= 0.2.0" } , "devDependencies": { "express": "2.3.x" diff --git a/test/browser.navigation.test.js b/test/browser.navigation.test.js index f04b8d8..635b8a5 100644 --- a/test/browser.navigation.test.js +++ b/test/browser.navigation.test.js @@ -293,11 +293,22 @@ module.exports = { }); }, - 'test .post(path) with passed body': function(done) { + 'test .post(path) with passed body string': function(done) { var browser = tobi.createBrowser(app); - browser.post('/form', {body: "foo=bar"}, function(res, $){ + browser.post('/form', {body: 'foo=bar'}, function(res, $){ res.should.have.status(200); - res.body.body.should.eql({foo:"bar"}); + res.body.body.should.eql({foo:'bar'}); + browser.should.have.property('path', '/form'); + browser.history.should.eql(['/form']); + done(); + }); + }, + + 'test .post(path) with passed body object': function(done) { + var browser = tobi.createBrowser(app); + browser.post('/form', {body: {foo:'bar'}}, function(res, $){ + res.should.have.status(200); + res.body.body.should.eql({foo:'bar'}); browser.should.have.property('path', '/form'); browser.history.should.eql(['/form']); done();