Skip to content

Commit

Permalink
MISC Update dev deps, small updates to README.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelax committed Apr 17, 2016
1 parent 25665c0 commit a920af5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 43 deletions.
29 changes: 14 additions & 15 deletions Readme.md
@@ -1,4 +1,4 @@
# SuperTest [![Build Status](https://travis-ci.org/visionmedia/supertest.svg?branch=master)](https://travis-ci.org/visionmedia/supertest) [![npm version](https://badge.fury.io/js/supertest.svg)](https://www.npmjs.com/package/supertest)
# SuperTest [![Build Status](https://travis-ci.org/visionmedia/supertest.svg?branch=master)](https://travis-ci.org/visionmedia/supertest) [![npm version](https://badge.fury.io/js/supertest.svg)](https://www.npmjs.com/package/supertest) [![Dependency Status](https://david-dm.org/visionmedia/supertest.svg)](https://david-dm.org/visionmedia/supertest)

HTTP assertions made easy via [super-agent](http://github.com/visionmedia/superagent).

Expand Down Expand Up @@ -26,12 +26,12 @@ npm install supertest --save-dev
test framework at all:

```js
var request = require('supertest')
, express = require('express');
var request = require('supertest');
var express = require('express');

var app = express();

app.get('/user', function(req, res){
app.get('/user', function(req, res) {
res.status(200).json({ name: 'tobi' });
});

Expand All @@ -40,23 +40,23 @@ request(app)
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
.end(function(err, res){
.end(function(err, res) {
if (err) throw err;
});
```

Here's an example with mocha, note how you can pass `done` straight to any of the `.expect()` calls:

```js
describe('GET /user', function(){
it('respond with json', function(done){
describe('GET /user', function() {
it('respond with json', function(done) {
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
})
})
});
});
```

One thing to note with the above statement is that superagent now sends any HTTP
Expand All @@ -68,13 +68,13 @@ you do not add a status code expect (i.e. `.expect(302)`).
order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows:

```js
describe('GET /users', function(){
it('respond with json', function(done){
describe('GET /users', function() {
it('respond with json', function(done) {
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect(200)
.end(function(err, res){
.end(function(err, res) {
if (err) return done(err);
done();
});
Expand All @@ -86,8 +86,8 @@ describe('GET /users', function(){
to modify the response body or headers before executing an assertion.

```js
describe('GET /user', function(){
it('user.name should be an case-insensitive match for "tobi"', function(done){
describe('GET /user', function() {
it('user.name should be an case-insensitive match for "tobi"', function(done) {
request(app)
.get('/user')
.set('Accept', 'application/json')
Expand All @@ -101,7 +101,6 @@ describe('GET /user', function(){
}, done);
});
});

```

Anything you can do with superagent, you can do with supertest - for example multipart file uploads!
Expand Down
20 changes: 0 additions & 20 deletions example.js

This file was deleted.

14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -12,13 +12,13 @@
"methods": "1.x"
},
"devDependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"eslint": "^2.5.3",
"eslint-config-airbnb": "^6.2.0",
"express": "~4.12.4",
"mocha": "~2.2.5",
"should": "~7.0.2"
"body-parser": "~1.15.0",
"cookie-parser": "~1.4.1",
"eslint": "^2.8.0",
"eslint-config-airbnb": "^7.0.0",
"express": "~4.13.4",
"mocha": "~2.4.5",
"should": "~8.3.1"
},
"engines": {
"node": ">=0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion test/supertest.js
Expand Up @@ -440,7 +440,7 @@ describe('request(app)', function() {
.expect(200)
.expect('hey')
.end(function(err, res) {
err.message.should.equal('expected 200 \"OK"\, got 500 \"Internal Server Error\"');
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"');
done();
});
});
Expand Down

0 comments on commit a920af5

Please sign in to comment.