Skip to content

Commit

Permalink
Added test case for response class
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinDmello committed Jan 17, 2018
1 parent b296442 commit 268f24c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
class Response {

send(data) {

if (typeof data != 'string' && typeof data != 'object') {
throw new Error("Cannot write anything except string or object")
}

if (typeof data === 'string') {
this.write(data)
}
Expand Down
49 changes: 49 additions & 0 deletions test/response-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Celer - An HTTP framework
* Copyright(c) 2017-present @GavinDmello
* MIT Licensed
*/

//Requiring the dev-dependencies
var chai = require('chai')
var expect = chai.expect
var assert = chai.assert

describe('checking response methods', () => {

const ResponseWrapper = require('../lib/response')
const responseWrapper = new ResponseWrapper()
responseWrapper.write = function(params) {}
responseWrapper.end = function(params) {}


it('with string param', (done) => {
try {
responseWrapper.send("Hello")
} catch (e) {
assert.fail("Error in response", "string param", e.toString())
}
done()
})

it('with object param', (done) => {
try {
responseWrapper.send({ a : 1})
} catch (e) {
assert.fail("Error in response", "object param", e.toString())
}
done()
})

it('with number param', (done) => {
try {
responseWrapper.send(1)
} catch (e) {
done()
return
}
assert.fail("should fail before", "numbers are not allowed", "")

})

})

0 comments on commit 268f24c

Please sign in to comment.