Skip to content

Commit

Permalink
tests: reorganize json error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 8, 2017
1 parent 5bd7ed5 commit 4e15325
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions test/json.js
Expand Up @@ -15,14 +15,6 @@ describe('bodyParser.json()', function () {
.expect(200, '{"user":"tobi"}', done)
})

it('should fail gracefully', function (done) {
request(createServer())
.post('/')
.set('Content-Type', 'application/json')
.send('{"user"')
.expect(400, parseError('{"user"'), done)
})

it('should handle Content-Length: 0', function (done) {
request(createServer())
.get('/')
Expand All @@ -47,14 +39,6 @@ describe('bodyParser.json()', function () {
.expect(200, '{}', done)
})

it('should 400 on malformed JSON', function (done) {
request(createServer())
.post('/')
.set('Content-Type', 'application/json')
.send('{:')
.expect(400, parseError('{:'), done)
})

it('should 400 when invalid content-length', function (done) {
var jsonParser = bodyParser.json()
var server = createServer(function (req, res, next) {
Expand Down Expand Up @@ -85,6 +69,28 @@ describe('bodyParser.json()', function () {
.expect(200, '{"user":"tobi"}', done)
})

describe('when JSON is invalid', function () {
before(function () {
this.server = createServer()
})

it('should 400 for bad token', function (done) {
request(this.server)
.post('/')
.set('Content-Type', 'application/json')
.send('{:')
.expect(400, parseError('{:'), done)
})

it('should 400 for incomplete', function (done) {
request(this.server)
.post('/')
.set('Content-Type', 'application/json')
.send('{"user"')
.expect(400, parseError('{"user"'), done)
})
})

describe('with limit option', function () {
it('should 413 when over limit with Content-Length', function (done) {
var buf = Buffer.alloc(1024, '.')
Expand Down

0 comments on commit 4e15325

Please sign in to comment.