UNPKG

2.06 kBJavaScriptView Raw
1
2/**
3 * Module dependencies.
4 */
5
6var should = require('../');
7var util = require('util');
8
9function err(fn, msg) {
10 try {
11 fn();
12 should.fail('expected an error');
13 } catch (err) {
14 should.equal(msg, err.message);
15 }
16}
17
18function err_should_exist(obj) {
19 err(function () {
20 should.exist(obj);
21 }, 'expected ' + util.inspect(obj) + ' to exist');
22}
23
24function err_should_not_exist(obj) {
25 err(function () {
26 should.not.exist(obj);
27 }, 'expected ' + util.inspect(obj) + ' to not exist');
28}
29
30module.exports = {
31
32 // static should.exist() pass:
33
34 'test static should.exist() pass w/ bool': function () {
35 should.exist(false);
36 },
37
38 'test static should.exist() pass w/ number': function () {
39 should.exist(0);
40 },
41
42 'test static should.exist() pass w/ string': function () {
43 should.exist('');
44 },
45
46 'test static should.exist() pass w/ object': function () {
47 should.exist({});
48 },
49
50 'test static should.exist() pass w/ array': function () {
51 should.exist([]);
52 },
53
54 // static should.exist() fail:
55
56 'test static should.exist() fail w/ null': function () {
57 err_should_exist(null);
58 },
59
60 'test static should.exist() fail w/ undefined': function () {
61 err_should_exist(undefined);
62 },
63
64 // static should.not.exist() pass:
65
66 'test static should.not.exist() pass w/ null': function () {
67 should.not.exist(null);
68 },
69
70 'test static should.not.exist() pass w/ undefined': function () {
71 should.not.exist(undefined);
72 },
73
74 // static should.not.exist() fail:
75
76 'test static should.not.exist() fail w/ bool': function () {
77 err_should_not_exist(false);
78 },
79
80 'test static should.not.exist() fail w/ number': function () {
81 err_should_not_exist(0);
82 },
83
84 'test static should.not.exist() fail w/ string': function () {
85 err_should_not_exist('');
86 },
87
88 'test static should.not.exist() fail w/ object': function () {
89 err_should_not_exist({});
90 },
91
92 'test static should.not.exist() fail w/ array': function () {
93 err_should_not_exist([]);
94 },
95
96};