Skip to content

Commit 03aa551

Browse files
committed
Add more tests
1 parent 980c23f commit 03aa551

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ each(
6060
{ log: true },
6161
{ unknown: true },
6262
{ classes: {} },
63+
{ custom: 'pretty' },
6364
],
6465
({ title }, options) => {
6566
test(`Options are validated | ${title}`, (t) => {
@@ -113,3 +114,26 @@ test.serial('Can use together with modern-errors-beautiful', (t) => {
113114
`${figures.cross} BothError: test`,
114115
)
115116
})
117+
118+
test.serial('Can use aggregate errors', (t) => {
119+
const { consoleArg } = errorExit(
120+
new BaseError('test', {
121+
cli: { icon: 'warning' },
122+
errors: [new BaseError('inner', { cli: { icon: 'info' } })],
123+
}),
124+
)
125+
t.true(consoleArg.includes(`${figures.warning} BaseError: test`))
126+
t.true(consoleArg.includes(`${figures.info} BaseError: inner`))
127+
})
128+
129+
test('Returns beautified errors, static', (t) => {
130+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
131+
const prettyMessage: string = BaseError.pretty(error)
132+
t.true(prettyMessage.includes(`${figures.cross} BaseError: test`))
133+
})
134+
135+
test('Returns beautified errors, instance', (t) => {
136+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
137+
const prettyMessage: string = error.pretty()
138+
t.true(prettyMessage.includes(`${figures.cross} BaseError: test`))
139+
})

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const exit = ({ error, options }: Info<Options>['instanceMethods']) => {
6161

6262
// Uses `.pretty()` to avoid conflict with `modern-errors-beautiful`.
6363
// Temporarily unsets `error.pretty()` to avoid recursion.
64+
// This is a workaround to support nested errors and is not documented.
6465
const pretty = ({
6566
error,
6667
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)