-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
87 lines (76 loc) · 2.24 KB
/
test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*!
* assert-kindof <https://github.com/tunnckoCore/assert-kindof>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var util = require('util')
var test = require('mukla')
var assert = require('./index')
test('should throws if not okey', function (done) {
try {
assert.object(null)
} catch (err) {
test.strictEqual(err.message, 'null !== object')
test.strictEqual(err.actual, 'null')
test.strictEqual(err.expected, 'object')
}
done()
})
test('should throws if negation not okey', function (done) {
try {
assert.not.number(123)
} catch (err) {
test.strictEqual(err.message, 'number === number')
}
done()
})
test('should not throw if okey', function (done) {
assert.string('foo')
done()
})
test('should allow custom assertion message', function (done) {
var msg = 'expect a function, but got object'
try {
assert.function({ foo: 'barrr' }, msg)
} catch (err) {
test.strictEqual(err.message, msg)
test.strictEqual(err.value.foo, 'barrr')
}
done()
})
test('should allow msg to be function', function (done) {
try {
assert.number({ aa: 'bb' }, function (actual, expected, value) {
test.strictEqual(actual, 'object')
test.strictEqual(expected, 'number')
test.strictEqual(value.aa, 'bb')
return 'expect value to be ' + expected + ', but got ' + util.inspect(value)
})
} catch (err) {
test.strictEqual(/expect value to be number, but got/.test(err.message), true)
}
done()
})
test('should support message to be template', function (done) {
try {
assert.function('foo', 'expect `bar` to be {expected}, but got {actual}')
} catch (err) {
test.strictEqual(err.message, 'expect `bar` to be function, but got string')
done()
}
})
test('should `assert.undefined()` not throws', function (done) {
assert.undefined()
done()
})
test('should expose `is-kindof` as `.is`', function (done) {
test.strictEqual(typeof assert.is, 'object')
test.strictEqual(typeof assert.is.string, 'function')
test.strictEqual(typeof assert.is.boolean, 'function')
test.strictEqual(assert.is.null('abc'), false)
test.strictEqual(assert.is.string('abc'), true)
done()
})