-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
86 lines (78 loc) · 2.42 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
/*!
* mukla <https://github.com/tunnckoCore/mukla>
*
* Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var test = require('assertit')
var mukla = require('./index')
var capture = require('capture-stream')
test('should throw TypeError if not at least function passed', function (done) {
function fixture () {
mukla(123)
}
test.throws(fixture, TypeError)
test.throws(fixture, /expect at least `fn` be function/)
done()
})
test('should expose function', function (done) {
test.strictEqual(typeof mukla, 'function')
done()
})
test('should expose assert methods', function (done) {
test.strictEqual(typeof mukla.strictEqual, 'function')
test.strictEqual(typeof mukla.deepEqual, 'function')
test.strictEqual(typeof mukla.equal, 'function')
test.strictEqual(typeof mukla.ok, 'function')
done()
})
test('should be able to have "unnamed" tests when only function passed', function (done) {
var restore = capture(process.stdout)
setTimeout(function () {
mukla(function (done) {
console.log('foo')
done()
})
}, 1)
setTimeout(function () {
var output = restore(true).trim()
test.strictEqual(/foo/.test(output), true)
test.strictEqual(/anonymous/.test(output), true)
done()
}, 2)
})
test('should be able to pass "named" tests when `name` and `fn` passed', function (done) {
var restore = capture(process.stdout)
setTimeout(function () {
mukla('foo bar test', function (done) {
console.log('here some assert')
done()
})
}, 1)
setTimeout(function () {
var out = restore(true)
test.ok(/here some assert/.test(out.trim()))
test.strictEqual(/foo bar test/.test(out.trim()), true)
done()
}, 2)
})
// works but architecture not allows cool and easy handling
//
// var path = require('path')
// test('should create TAP-compliant error outputs', function (done) {
// var restore = capture(process.stdout)
// setTimeout(function () {
// mukla('foo bar test', function someMuklaTest (cb) {
// path.resolve(123)
// cb()
// }/* , true */) // pass `true` as third argument to print stack traces
// }, 1)
// setTimeout(function () {
// var out = restore(true)
// test.ok(/name: TypeError/.test(out))
// test.ok(/message: Path must be a string/.test(out))
// test.ok(/at: Function\.someMuklaTest/.test(out))
// done()
// }, 2)
// })