Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds tests for status and type.

  • Loading branch information...
commit 0256b52e7c4e0ca5f4c4a1e9c601f71c52549cef 1 parent a699f5a
@cpsubrian authored
Showing with 54 additions and 15 deletions.
  1. +15 −15 test/common.js
  2. +21 −0 test/status.js
  3. +18 −0 test/type.js
View
30 test/common.js
@@ -7,29 +7,29 @@ supertest = require('supertest');
var server;
-response = function () {
- var res = clone(expres.methods);
- res.__proto__ = http.ServerResponse.prototype;
- return res;
-};
-
-get = function (path, cb) {
- request().get(path).set('Host', 'example.com').end(cb);
+createServer = function (done) {
+ server = http.createServer(expres.middleware).listen(9000, done);
};
-request = function () {
- return supertest(server);
+closeServer = function (done) {
+ server.close();
+ done();
};
respond = function (cb) {
server.on('request', cb);
};
-createServer = function (done) {
- server = http.createServer(expres.middleware).listen(9000, done);
+request = function () {
+ return supertest(server);
};
-closeServer = function (done) {
- server.close();
- done();
+get = function (path, cb) {
+ request().get(path).set('Host', 'example.com').end(cb);
+};
+
+response = function () {
+ var res = clone(expres.methods);
+ res.__proto__ = http.ServerResponse.prototype;
+ return res;
};
View
21 test/status.js
@@ -0,0 +1,21 @@
+describe('status', function(){
+
+ beforeEach(createServer);
+ afterEach(closeServer);
+
+ describe('.status(code)', function(){
+ it('should set the response .statusCode', function(done){
+ respond(function(req, res){
+ res.status(201).send('Created');
+ });
+
+ request()
+ .get('/')
+ .end(function (err, res) {
+ assert.equal(res.statusCode, 201);
+ assert.equal(res.text, 'Created');
+ done();
+ });
+ });
+ });
+});
View
18 test/type.js
@@ -0,0 +1,18 @@
+describe('type', function(){
+
+ beforeEach(createServer);
+ afterEach(closeServer);
+
+ describe('.type(str)', function(){
+ it('should set the Content-Type with type/subtype', function(done){
+ respond(function(req, res){
+ res.type('application/vnd.amazon.ebook')
+ .send('var name = "tj";');
+ });
+
+ request()
+ .get('/')
+ .expect('Content-Type', 'application/vnd.amazon.ebook', done);
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.