issue-31.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function () {
  2. /*global describe, it*/
  3. 'use strict';
  4. var should = require('should'),
  5. express = require('express'),
  6. supertest = require('supertest'),
  7. cors = require('../lib');
  8. var app,
  9. mainRouter,
  10. itemsRouter;
  11. /* -------------------------------------------------------------------------- */
  12. itemsRouter = new express.Router();
  13. itemsRouter.get('/', function (req, res) {
  14. res.send('hello world');
  15. });
  16. mainRouter = new express.Router();
  17. mainRouter.use('/items', itemsRouter);
  18. app = express();
  19. app.use(cors());
  20. app.use(mainRouter);
  21. /* -------------------------------------------------------------------------- */
  22. describe('issue #31', function () {
  23. it('OPTIONS works', function (done) {
  24. supertest(app)
  25. .options('/items')
  26. .expect(204)
  27. .set('Origin', 'http://example.com')
  28. .end(function (err, res) {
  29. should.not.exist(err);
  30. res.headers['access-control-allow-origin'].should.eql('*');
  31. done();
  32. });
  33. });
  34. it('GET works', function (done) {
  35. supertest(app)
  36. .get('/items')
  37. .expect(200)
  38. .set('Origin', 'http://example.com')
  39. .end(function (err, res) {
  40. should.not.exist(err);
  41. res.headers['access-control-allow-origin'].should.eql('*');
  42. res.text.should.eql('hello world');
  43. done();
  44. });
  45. });
  46. });
  47. }());