Skip to content

Commit 199e476

Browse files
committed
Added comment for mock onError
Added check for arg getting used
1 parent 4798aef commit 199e476

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/language-server/src/__test__/artificial-panic.test.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,21 @@ suite('Artificial Panics', () => {
3939
process.env.FORCE_PANIC_PRISMA_FMT = '1'
4040

4141
let calledCount = 0
42+
let calledArg: undefined | unknown = undefined
4243

43-
const onError = () => {
44+
// No official mock implementation in mocha
45+
// -> DIY mock for onError
46+
const onError = (arg: unknown) => {
4447
calledCount += 1
48+
calledArg = arg
4549
}
4650

4751
try {
4852
const _codeActions = handleCodeActions(params, document, onError)
4953

5054
assert.fail("This shouldn't happen!")
5155
} catch (e) {
56+
assert.ok(calledArg)
5257
assert.ok(calledCount == 1)
5358
} finally {
5459
process.env = { ...OLD_ENV }
@@ -70,16 +75,19 @@ suite('Artificial Panics', () => {
7075
process.env.FORCE_PANIC_PRISMA_FMT = '1'
7176

7277
let calledCount = 0
78+
let calledArg: undefined | unknown = undefined
7379

74-
const onError = () => {
80+
const onError = (arg: unknown) => {
7581
calledCount += 1
82+
calledArg = arg
7683
}
7784

7885
try {
7986
const _formatResult: TextEdit[] = handleDocumentFormatting(params, document, onError)
8087

8188
assert.fail("This shouldn't happen!")
8289
} catch (e) {
90+
assert.ok(calledArg)
8391
assert.ok(calledCount == 1)
8492
} finally {
8593
process.env = { ...OLD_ENV }
@@ -93,16 +101,19 @@ suite('Artificial Panics', () => {
93101
process.env.FORCE_PANIC_PRISMA_FMT = '1'
94102

95103
let calledCount = 0
104+
let calledArg: undefined | unknown = undefined
96105

97-
const onError = () => {
106+
const onError = (arg: unknown) => {
98107
calledCount += 1
108+
calledArg = arg
99109
}
100110

101111
try {
102112
const _diagnostics = handleDiagnosticsRequest(document, onError)
103113

104114
assert.fail("This shouldn't happen!")
105115
} catch (e) {
116+
assert.ok(calledArg)
106117
assert.ok(calledCount == 1)
107118
} finally {
108119
process.env = { ...OLD_ENV }
@@ -132,16 +143,19 @@ suite('Artificial Panics', () => {
132143
process.env.FORCE_PANIC_PRISMA_FMT_LOCAL = '1'
133144

134145
let calledCount = 0
146+
let calledArg: undefined | unknown = undefined
135147

136-
const onError = () => {
148+
const onError = (arg: unknown) => {
137149
calledCount += 1
150+
calledArg = arg
138151
}
139152

140153
try {
141154
const _completions = handleCompletionRequest(params, document, onError)
142155

143156
assert.fail("This shouldn't happen!")
144157
} catch (e) {
158+
assert.ok(calledArg)
145159
assert.ok(calledCount == 1)
146160
} finally {
147161
process.env = { ...OLD_ENV }
@@ -171,16 +185,19 @@ suite('Artificial Panics', () => {
171185
process.env.FORCE_PANIC_PRISMA_FMT_LOCAL = '1'
172186

173187
let calledCount = 0
188+
let calledArg: undefined | unknown = undefined
174189

175-
const onError = () => {
190+
const onError = (arg: unknown) => {
176191
calledCount += 1
192+
calledArg = arg
177193
}
178194

179195
try {
180196
const _completions = handleCompletionRequest(params, document, onError)
181197

182198
assert.fail("This shouldn't happen!")
183199
} catch (e) {
200+
assert.ok(calledArg)
184201
assert.ok(calledCount == 1)
185202
} finally {
186203
process.env = { ...OLD_ENV }
@@ -199,16 +216,19 @@ suite('Artificial Panics', () => {
199216
process.env.FORCE_PANIC_PRISMA_FMT = '1'
200217

201218
let calledCount = 0
219+
let calledArg: undefined | unknown = undefined
202220

203-
const onError = () => {
221+
const onError = (arg: unknown) => {
204222
calledCount += 1
223+
calledArg = arg
205224
}
206225

207226
try {
208227
const _completions = handleCompletionRequest(params, document, onError)
209228

210229
assert.fail("This shouldn't happen!")
211230
} catch (e) {
231+
assert.ok(calledArg)
212232
assert.ok(calledCount == 1)
213233
} finally {
214234
process.env = { ...OLD_ENV }

0 commit comments

Comments
 (0)