沈斌
2018-07-10 f00a2b2acc1480c21234001c78da43eec48683d1
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
36
37
require('./spec_helper');
var expressPromise = require('..');
 
describe('skip rule', function() {
  it('should skip traverse the object', function(done) {
    var res = {
      json: function(body) {
        body.a.b.should.equal('hi');
        body.a.c.name.should.equal('lib');
        done();
      }
    };
    expressPromise({methods: ['json'], skipTraverse: function(object) {
      return object.hasOwnProperty('name');
    }})(null, res);
 
    function async(callback) {
      callback(null, 'hi');
    }
 
    res.json({
      a: {
        b: async.promise(),
        c: {
          name: 'lib',
          d: async.promise(),
          toJSON: function() {
            return {
              f: 'hi'
            };
          }
        }
      }
    });
  });
 
});