UNPKG

2.48 kBJavaScriptView Raw
1"use strict";
2describe("the basic stuff", function () {
3 var opinion = require('../');
4 it("should just load", function (done) {
5 var app = opinion();
6 app.listen("6557", function () {
7 app.theServer.close();
8 done();
9 });
10 });
11
12
13 it("should allow to get boud websockets", function (done) {
14 var app = opinion();
15 var sentinal = 0;
16 app.listen("6557", function () {
17 expect(sentinal).to.equal(1);
18 app.theServer.close();
19 done();
20 });
21 app.on('webSockets-bound', function () {
22 sentinal++;
23 expect(app).to.have.property('webSockets');
24 });
25 });
26
27
28 it("should allow `connect` style middleware", function (done) {
29 var opinion = require('../');
30 var app = opinion();
31 app.onerror = function (err, ctx) {
32 ctx.res.headersSent = true;
33 console.log('context got error - ', ctx.url);
34 throw err;
35 };
36 app.use(function (req, res, next) {
37 next();
38 });
39 app.mock({url: '/gaga3'}, done);
40 });
41
42
43 it("should allow async `connect` style middleware", function (done) {
44 var opinion = require('../');
45 var app = opinion();
46 app.onerror = function (err, ctx) {
47 ctx.res.headersSent = true;
48 console.log('context got error - ', ctx.url);
49 throw err;
50 };
51 app.use(function (req, res, next) {
52 setImmediate(function () {
53 res.guli = true;
54 next();
55 });
56 });
57 app.use(function (req, res, next) {
58 expect(res.guli).to.equal(true);
59 next();
60 });
61 app.mock({url: '/gaga3a'}, done);
62 });
63
64
65 it("should handle exception form async `connect` style middleware", function (done) {
66 var opinion = require('../');
67 var app = opinion();
68 app.onerror = function (err, ctx) {
69 ctx.res.headersSent = true;
70 expect(err).to.be.instanceof(Error);
71 done();
72 };
73 app.use(function (req, res, next) {
74 setImmediate(function () {
75 res.guli = true;
76 next(new Error('gaga3a'));
77 });
78 });
79 app.use(function (req, res, next, err) {
80 expect(res.guli).to.equal(true);
81 next();
82 });
83 app.mock({url: '/gaga3a'});
84 });
85});