get.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. let request = require('../index');
  2. let http = require('http');
  3. let assert = require('assert');
  4. let server = http.createServer(function (req, res) {
  5. res.writeHead(200, { 'content-type': 'text/plain' });
  6. res.end('Hello, world!\n');
  7. });
  8. describe('/GET', function () {
  9. before(function () {
  10. server.listen(8000);
  11. });
  12. describe('/', function () {
  13. it('should return 200', function (done) {
  14. request.get('http://localhost:8000/?hey=d', function(err, data, status, headers) {
  15. assert.ifError(err);
  16. assert.equal(200, status);
  17. done();
  18. });
  19. });
  20. it('should say "Hello, world!"', function (done) {
  21. request.get("http://localhost:8000", function(err, data, status, headers) {
  22. assert.ifError(err);
  23. assert.equal('Hello, world!\n', data);
  24. done();
  25. });
  26. });
  27. it("should have content-type to 'text/plain'", function (done) {
  28. request.get("http://localhost:8000",function(err, data, status, headers) {
  29. assert.ifError(err);
  30. assert.equal('text/plain' , headers['content-type']);
  31. done();
  32. });
  33. });
  34. });
  35. after(function () {
  36. server.close();
  37. });
  38. });