This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
102 lines (84 loc) · 2.96 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict'
const test = require('tape')
const errors = require('.')
test('all errors are instances of Error and LevelUPError', function (t) {
const LevelUPError = errors.LevelUPError
const keys = Object.keys(errors)
keys.forEach(function (key) {
t.ok(new errors[key]() instanceof Error)
t.ok(new errors[key]() instanceof LevelUPError)
})
t.end()
})
test('error with message has expected properties', function (t) {
const error = new errors.ReadError('foo')
t.is(error.type, 'ReadError')
t.is(error.name, 'ReadError')
t.is(error.cause, undefined)
t.is(error.message, 'foo')
t.end()
})
test('error without message has expected properties', function (t) {
const error = new errors.ReadError()
t.is(error.type, 'ReadError')
t.is(error.name, 'ReadError')
t.is(error.cause, undefined)
t.is(error.message, '')
t.end()
})
test('error with cause has expected properties', function (t) {
const cause = new Error('foo')
const error = new errors.ReadError(cause)
t.is(error.type, 'ReadError')
t.is(error.name, 'ReadError')
t.is(error.cause, cause)
t.is(error.message, 'foo')
t.end()
})
test('error with message and cause has expected properties', function (t) {
const cause = new Error('foo')
const error = new errors.ReadError('bar', cause)
t.is(error.type, 'ReadError')
t.is(error.name, 'ReadError')
t.is(error.cause, cause)
t.is(error.message, 'bar')
t.end()
})
test('NotFoundError has special properties', function (t) {
const error = new errors.NotFoundError()
t.is(error.notFound, true)
t.is(error.status, 404)
t.end()
})
test('error message is writable to mirror node core conventions', function (t) {
const error = new errors.WriteError('foo')
error.message = 'Got error: ' + error.message
t.is(error.message, 'Got error: foo')
t.end()
})
test('returns original instance if cause is the same type', function (t) {
const cause = new errors.NotFoundError('Key not found in database [foo]')
const error = new errors.NotFoundError(cause)
t.is(cause, error, 'same instance')
t.is(error.message, 'Key not found in database [foo]')
t.end()
})
test('returns new instance if cause prototype is different', function (t) {
const cause = new errors.NotFoundError('Key not found in database [foo]')
const error = new errors.WriteError(cause)
t.isNot(cause, error, 'new instance')
t.is(error.message, 'Key not found in database [foo]')
t.end()
})
test('returns original instance if message and cause are the same', function (t) {
const cause = new errors.NotFoundError('Key not found in database [foo]')
const error = new errors.NotFoundError('Key not found in database [foo]', cause)
t.is(cause, error, 'same instance')
t.end()
})
test('returns new instance if message is different', function (t) {
const cause = new errors.NotFoundError('Key not found in database [foo]')
const error = new errors.NotFoundError('Key not found in database [bar]', cause)
t.isNot(cause, error, 'new instance')
t.end()
})