Zombie is more suitable for interacting with actual web pages, and in the case of actual post request forms.
For your testing, use the request module and manually create a submit request
var request = require('request') var should = require('should') describe('URL names', function () { it('Should give error on invalid url', function(done) { // assume the following url is invalid var url = 'http://localhost:5000/api/names' var opts = { url: url, method: 'post' } request(opts, function (err, res, body) { // you will need to customize the assertions below based on your server // if server returns an actual error should.exist(err) // maybe you want to check the status code res.statusCode.should.eql(404, 'wrong status code returned from server') done() }) }) it('Should not give error on valid url', function(done) { // assume the following url is valid var url = 'http://localhost:5000/api/foo' var opts = { url: url, method: 'post' } request(opts, function (err, res, body) { // you will need to customize the assertions below based on your server // if server returns an actual error should.not.exist(err) // maybe you want to check the status code res.statusCode.should.eql(200, 'wrong status code returned from server') done() }) }) })
For the code above, you need request and should modules
npm install
source share