沈斌
2018-07-10 c347a3cf58b27a1ab267517fa9effbb7d477626b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require('./spec_helper');
var expressPromise = require('..');
 
describe('basic', function() {
  it('should use the toJSON method', function(done) {
    var res = {
      json: function(body) {
        body.a.b.should.equal('hi');
        body.a.c.should.not.have.property('d');
        body.a.c.f.should.equal('hi');
        done();
      }
    };
    expressPromise({methods: ['json']})(null, res);
 
    function async(callback) {
      callback(null, 'hi');
    }
 
    res.json({
      a: {
        b: async.promise(),
        c: {
          d: async.promise(),
          toJSON: function() {
            return {
              f: 'hi'
            };
          }
        }
      }
    });
  });
 
});