This repository has been archived by the owner on Mar 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
elementary.js
65 lines (42 loc) · 1.6 KB
/
elementary.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
var _deepEqual = require('./deep-equal')._deepEqual //pulled from node
, fail = require('./failure').fail
//elementary assertions.
module.exports = {
equal: function (actual, expected, message) {
if(!(actual == expected))
throw fail(new Error()).simple('equal', actual, expected, '==', message)
},
notEqual: function (actual, expected, message) {
if(actual == expected)
throw fail(new Error()).simple('notEqual', actual, expected, '!=', message)
},
strictEqual: function (actual, expected, message) {
if(!(actual === expected))
throw fail(new Error()).simple('strictEqual', actual, expected, '===', message)
},
notStrictEqual: function (actual, expected, message) {
if(actual === expected)
throw fail(new Error()).simple('notStrictEqual', actual, expected, '!==', message)
},
ok: function (actual, message) {
if(!(!!actual))
throw fail(new Error()).explain('ok: {actual:render} must be truthy', {actual: actual}, message)
},
deepEqual: function (actual, expected, message) {
if(!_deepEqual(actual, expected))
throw (
fail(new Error())
.explain('deepEqual: {actual:render} must deepEqual {expected:render}'
, {actual: actual, expected: expected}, message)
)
},
notDeepEqual: function (actual, expected, message) {
if(_deepEqual(actual, expected))
throw (
fail(new Error())
.explain('deepEqual: {actual:render} must not deepEqual {expected:render}'
, {actual: actual, expected: expected}, message)
)
}
}
exports['ifError'] = exports.ok