This repository has been archived by the owner on Nov 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
/
assert.js
71 lines (66 loc) · 1.63 KB
/
assert.js
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
/*
* should.js - assertion library
* Copyright(c) 2010-2013 TJ Holowaychuk <tj@vision-media.ca>
* Copyright(c) 2013-2017 Denis Bardadym <bardadymchik@gmail.com>
* MIT Licensed
*/
import { merge } from 'should-util';
import assert from './_assert';
import AssertionError from '../assertion-error';
export default function(should) {
var i = should.format;
/*
* Expose assert to should
*
* This allows you to do things like below
* without require()ing the assert module.
*
* should.equal(foo.bar, undefined);
*
*/
merge(should, assert);
/**
* Assert _obj_ exists, with optional message.
*
* @static
* @memberOf should
* @category assertion assert
* @alias should.exists
* @param {*} obj
* @param {String} [msg]
* @example
*
* should.exist(1);
* should.exist(new Date());
*/
should.exist = should.exists = function(obj, msg) {
if (null == obj) {
throw new AssertionError({
message: msg || ('expected ' + i(obj) + ' to exist'), stackStartFunction: should.exist
});
}
};
should.not = {};
/**
* Asserts _obj_ does not exist, with optional message.
*
* @name not.exist
* @static
* @memberOf should
* @category assertion assert
* @alias should.not.exists
* @param {*} obj
* @param {String} [msg]
* @example
*
* should.not.exist(null);
* should.not.exist(void 0);
*/
should.not.exist = should.not.exists = function(obj, msg) {
if (null != obj) {
throw new AssertionError({
message: msg || ('expected ' + i(obj) + ' to not exist'), stackStartFunction: should.not.exist
});
}
};
}