Skip to content

Commit 0b45929

Browse files
committed
Simplify tests
1 parent f7511fa commit 0b45929

File tree

2 files changed

+2
-150
lines changed

2 files changed

+2
-150
lines changed

types/main.d.ts

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,7 @@
11
import type { Info } from 'modern-errors'
2+
import type { Options, HttpResponse } from 'error-http-response'
23

3-
/**
4-
* Options of `modern-errors-http`
5-
*/
6-
export interface Options {
7-
/**
8-
* URI identifying and documenting the error class. Ideally, each error class
9-
* [should set one](https://github.com/ehmicky/modern-errors/README.md#plugin-options).
10-
*
11-
* @default undefined
12-
*/
13-
readonly type?: string
14-
15-
/**
16-
* HTTP status code.
17-
*
18-
* @default undefined
19-
*/
20-
readonly status?: number
21-
22-
/**
23-
* Error class name.
24-
*
25-
* @default error.name
26-
*/
27-
readonly title?: string
28-
29-
/**
30-
* Error description.
31-
*
32-
* @default error.message
33-
*/
34-
readonly detail?: string
35-
36-
/**
37-
* URI identifying the value which errored.
38-
*
39-
* @default undefined
40-
*/
41-
readonly instance?: string
42-
43-
/**
44-
* Error stack trace. Can be set to an empty string.
45-
*
46-
* @default error.stack
47-
*/
48-
readonly stack?: string
49-
50-
/**
51-
* Additional information. This is always
52-
* [safe to serialize as JSON](https://github.com/ehmicky/safe-json-value).
53-
* Can be set to an empty object.
54-
*
55-
* @default any additional `error` properties
56-
*/
57-
readonly extra?: object
58-
}
59-
60-
/**
61-
* `BaseError.httpResponse(error)`'s return value
62-
*/
63-
export interface HttpResponse extends Options {
64-
readonly title: string
65-
readonly detail: string
66-
readonly stack: string
67-
}
4+
export type { Options, HttpResponse }
685

696
/**
707
* `modern-errors-http` plugin

types/main.test-d.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,6 @@ expectError(
3030
expectError(BaseError.httpResponse(error, { unknown: true }))
3131
expectNotAssignable<Options>({ unknown: true })
3232

33-
ModernError.subclass('TestError', { plugins: [plugin], http: { type: '' } })
34-
BaseError.httpResponse(error, { type: '' })
35-
expectAssignable<Options>({ type: '' })
36-
expectError(
37-
ModernError.subclass('TestError', {
38-
plugins: [plugin],
39-
http: { type: true },
40-
}),
41-
)
42-
expectError(BaseError.httpResponse(error, { type: true }))
43-
expectNotAssignable<Options>({ type: true })
44-
45-
ModernError.subclass('TestError', { plugins: [plugin], http: { status: 200 } })
46-
BaseError.httpResponse(error, { status: 200 })
47-
expectAssignable<Options>({ status: 200 })
48-
expectError(
49-
ModernError.subclass('TestError', {
50-
plugins: [plugin],
51-
http: { status: true },
52-
}),
53-
)
54-
expectError(BaseError.httpResponse(error, { status: true }))
55-
expectNotAssignable<Options>({ status: true })
56-
5733
ModernError.subclass('TestError', { plugins: [plugin], http: { title: '' } })
5834
BaseError.httpResponse(error, { title: '' })
5935
expectAssignable<Options>({ title: '' })
@@ -66,69 +42,8 @@ expectError(
6642
expectError(BaseError.httpResponse(error, { title: true }))
6743
expectNotAssignable<Options>({ title: true })
6844

69-
ModernError.subclass('TestError', { plugins: [plugin], http: { detail: '' } })
70-
BaseError.httpResponse(error, { detail: '' })
71-
expectAssignable<Options>({ detail: '' })
72-
expectError(
73-
ModernError.subclass('TestError', {
74-
plugins: [plugin],
75-
http: { detail: true },
76-
}),
77-
)
78-
expectError(BaseError.httpResponse(error, { detail: true }))
79-
expectNotAssignable<Options>({ detail: true })
80-
81-
ModernError.subclass('TestError', { plugins: [plugin], http: { instance: '' } })
82-
BaseError.httpResponse(error, { instance: '' })
83-
expectAssignable<Options>({ instance: '' })
84-
expectError(
85-
ModernError.subclass('TestError', {
86-
plugins: [plugin],
87-
http: { instance: true },
88-
}),
89-
)
90-
expectError(BaseError.httpResponse(error, { instance: true }))
91-
expectNotAssignable<Options>({ instance: true })
92-
93-
ModernError.subclass('TestError', { plugins: [plugin], http: { stack: '' } })
94-
BaseError.httpResponse(error, { stack: '' })
95-
expectAssignable<Options>({ stack: '' })
96-
expectError(
97-
ModernError.subclass('TestError', {
98-
plugins: [plugin],
99-
http: { stack: true },
100-
}),
101-
)
102-
expectError(BaseError.httpResponse(error, { stack: true }))
103-
expectNotAssignable<Options>({ stack: true })
104-
105-
ModernError.subclass('TestError', { plugins: [plugin], http: { extra: {} } })
106-
BaseError.httpResponse(error, { extra: {} })
107-
expectAssignable<Options>({ extra: {} })
108-
ModernError.subclass('TestError', {
109-
plugins: [plugin],
110-
http: { extra: { prop: true } },
111-
})
112-
BaseError.httpResponse(error, { extra: { prop: true } })
113-
expectAssignable<Options>({ extra: { prop: true } })
114-
expectError(
115-
ModernError.subclass('TestError', {
116-
plugins: [plugin],
117-
http: { extra: true },
118-
}),
119-
)
120-
expectError(BaseError.httpResponse(error, { extra: true }))
121-
expectNotAssignable<Options>({ extra: true })
122-
12345
expectType<HttpResponse>(httpResponse)
124-
expectType<string | undefined>(httpResponse.type)
125-
expectType<number | undefined>(httpResponse.status)
12646
expectType<string>(httpResponse.title)
127-
expectType<string>(httpResponse.detail)
128-
expectType<string | undefined>(httpResponse.instance)
129-
expectType<string>(httpResponse.stack)
130-
expectType<object | undefined>(httpResponse.extra)
131-
expectError(httpResponse.extra?.prop)
13247

13348
expectType<HttpResponse>(error.httpResponse())
13449
expectError(error.httpResponse(true))

0 commit comments

Comments
 (0)