summaryrefslogtreecommitdiff
path: root/node_modules/should/test/exist.test.js
blob: 7aa1082007edbab92d0d79ba99ce19c120bd3064 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
 * Module dependencies.
 */

var should = require('../');
var util = require('util');

function err(fn, msg) {
  try {
    fn();
    should.fail('expected an error');
  } catch (err) {
    should.equal(msg, err.message);
  }
}

function err_should_exist(obj) {
  err(function () {
    should.exist(obj);
  }, 'expected ' + util.inspect(obj) + ' to exist');
}

function err_should_not_exist(obj) {
  err(function () {
    should.not.exist(obj);
  }, 'expected ' + util.inspect(obj) + ' to not exist');
}

module.exports = {
  
  // static should.exist() pass:
  
  'test static should.exist() pass w/ bool': function () {
    should.exist(false);
  },
  
  'test static should.exist() pass w/ number': function () {
    should.exist(0);
  },
  
  'test static should.exist() pass w/ string': function () {
    should.exist('');
  },
  
  'test static should.exist() pass w/ object': function () {
    should.exist({});
  },
  
  'test static should.exist() pass w/ array': function () {
    should.exist([]);
  },
  
  // static should.exist() fail:
  
  'test static should.exist() fail w/ null': function () {
    err_should_exist(null);
  },
  
  'test static should.exist() fail w/ undefined': function () {
    err_should_exist(undefined);
  },
  
  // static should.not.exist() pass:
  
  'test static should.not.exist() pass w/ null': function () {
    should.not.exist(null);
  },
  
  'test static should.not.exist() pass w/ undefined': function () {
    should.not.exist(undefined);
  },
  
  // static should.not.exist() fail:
  
  'test static should.not.exist() fail w/ bool': function () {
    err_should_not_exist(false);
  },
  
  'test static should.not.exist() fail w/ number': function () {
    err_should_not_exist(0);
  },
  
  'test static should.not.exist() fail w/ string': function () {
    err_should_not_exist('');
  },
  
  'test static should.not.exist() fail w/ object': function () {
    err_should_not_exist({});
  },
  
  'test static should.not.exist() fail w/ array': function () {
    err_should_not_exist([]);
  },
  
};