/
test.js
52 lines (46 loc) · 1.22 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
/*!
* catchup <https://github.com/tunnckoCore/catchup>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var fs = require('fs')
var test = require('assertit')
var catchup = require('./index')
var Catchup = require('./index').Catchup
test('should handle basic errors', function (done) {
var domain = new Catchup()
domain.once('error', function (err) {
test.ifError(!err)
test.ok(err instanceof Error)
test.equal(err.message, 'foo bar')
test.equal(domain.errored, true)
done()
})
domain.run(function () {
throw new Error('foo bar')
})
})
test('should handle ENOENT errors', function (done) {
var domain = catchup()
domain.once('error', function (err) {
test.ok(err instanceof Error)
test.equal(err.code, 'ENOENT')
test.equal(domain.errored, true)
done()
})
domain.run(function () {
fs.createReadStream('foo bar')
})
})
test('should have static `.create` method', function (done) {
var domain = Catchup.create()
var res = domain.run(function () {
return 'foo bar baz qux'
})
test.equal(res, 'foo bar baz qux')
test.equal(domain.errored, false)
done()
})