Created
August 18, 2015 11:21
-
-
Save Hochul822/741bdf49a03c90de3516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest'); | |
var express = require('express'); | |
var app = express(); | |
app.get('/users', function(req, res){ | |
res.send(200, { name : 'tobi'}); | |
}); | |
// get 함수를 통해 users에 request한 값이 잘 들어오는지 확인합니다. | |
// expect는 들어온 값들이 예상한(expect)한 값과 일치하는지 확인합니다. | |
request(app) | |
.get('/users') | |
.expect('Content-Type', /json/) // Content-Type이 json인지 확인 | |
.expect('Content-Length', '15') // Content-Length가 15인지 확인 | |
.expect(200) // response code가 200인지 확인합니다. | |
.end(function(err, res){ | |
if(err) throw err; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest'); | |
var express = require('express'); | |
var app = express(); | |
app.get('/users', function(req, res){ | |
res.send(200, { name : 'tobi'}); | |
}); | |
describe('GET /users', function(){ | |
it('respond with json', function(done){ | |
request(app) | |
.get('/users') | |
.expect('Content-Type', /json/) | |
.expect('Content-Length', '15') | |
.expect(200) | |
.end(function(err, res){ | |
if(err) throw err; | |
done(); // mocha를 쓸 때는 반드시 done이 있어야합니다. | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment