Skip to content

Commit dfea2d7

Browse files
committed
Add a test
1 parent 60d47bb commit dfea2d7

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/main.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { each } from 'test-each'
55

66
import modernErrorsBeautiful from 'modern-errors-beautiful'
77

8-
const message = 'test'
9-
108
const BaseError = ModernError.subclass('BaseError', {
119
plugins: [modernErrorsBeautiful],
1210
})
13-
const error = new BaseError(message)
11+
const ExitCodeError = BaseError.subclass('ExitCodeError', {
12+
beautiful: { icon: 'warning' },
13+
})
14+
const DatabaseError = BaseError.subclass('DatabaseError', {
15+
beautiful: { icon: 'info' },
16+
})
17+
const error = new BaseError('test')
1418

1519
each(
1620
[true, { stack: 'true' }, { unknown: true }, { classes: {} }],
@@ -41,8 +45,16 @@ test('Can pass "icon" as static option', (t) => {
4145
})
4246

4347
test('Can pass "icon" as class option', (t) => {
44-
const ExitCodeError = BaseError.subclass('ExitCodeError', {
45-
beautiful: { icon: 'warning' },
46-
})
47-
t.true(BaseError.beautiful(new ExitCodeError('')).includes(figures.warning))
48+
t.true(
49+
BaseError.beautiful(new ExitCodeError('test')).includes(figures.warning),
50+
)
51+
})
52+
53+
test('Can use aggregate errors', (t) => {
54+
const inner = new DatabaseError('inner')
55+
const outer = new ExitCodeError('test', { errors: [inner] })
56+
const message = BaseError.beautiful(inner)
57+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
58+
t.is(message, outer.beautiful())
59+
t.true(message.includes(figures.warning))
4860
})

0 commit comments

Comments
 (0)