Skip to content

Commit e6ade1d

Browse files
committed
Fix error assertions
1 parent 8d92a62 commit e6ade1d

24 files changed

+48
-45
lines changed

src/evaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type ExpressionErrorResponse = ErrorResponse & {
7575
}
7676

7777
export class ExpressionError extends EvaluationError<ExpressionErrorResponse> {
78-
constructor(response: ExpressionErrorResponse) {
78+
public constructor(response: ExpressionErrorResponse) {
7979
super(response);
8080

8181
Object.setPrototypeOf(this, ExpressionError.prototype);

test/channel/guaranteedChannel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('A guaranteed channel', () => {
5454
// Invalid acknowledge stamp
5555
sandboxChannel.notify('pong_stamp');
5656

57-
await expect(promise).rejects.toThrowError('Maximum confirmation time reached.');
57+
await expect(promise).rejects.toThrow('Maximum confirmation time reached.');
5858
});
5959

6060
test('should stop waiting for confirmation if the channel is closed in the meanwhile', async () => {

test/channel/queuedChannel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('A queued channel', () => {
101101
};
102102
const channel = new QueuedChannel(outputChannel, new CapacityRestrictedQueue(new InMemoryQueue('foo'), 1));
103103

104-
await expect(channel.publish('bar')).rejects.toThrowError(new Error('The queue is full.'));
104+
await expect(channel.publish('bar')).rejects.toThrow('The queue is full.');
105105
});
106106

107107
test('should fail to publish messages if the channel is closed', async () => {

test/channel/socketChannel.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('A socket channel', () => {
3232

3333
await channel.close();
3434

35-
await expect(channel.publish('bar')).rejects.toThrowError('Channel has been closed.');
35+
await expect(channel.publish('bar')).rejects.toThrow('Channel has been closed.');
3636
});
3737

3838
test('should fail to publish messages if an error occurs in the meanwhile', async () => {
@@ -187,7 +187,7 @@ describe('A socket channel', () => {
187187

188188
const channel = new SocketChannel({url: url, connectionTimeout: 100});
189189

190-
await expect(channel.publish('timeout')).rejects.toThrowError('Maximum connection timeout reached.');
190+
await expect(channel.publish('timeout')).rejects.toThrow('Maximum connection timeout reached.');
191191

192192
expect(close).toHaveBeenCalledWith(1000, 'Maximum connection timeout reached.');
193193
});
@@ -199,7 +199,7 @@ describe('A socket channel', () => {
199199
await channel.publish('open connection');
200200
await server.connected;
201201

202-
await expect(channel.close()).rejects.toThrowError('Maximum close timeout reached.');
202+
await expect(channel.close()).rejects.toThrow('Maximum close timeout reached.');
203203
});
204204

205205
test('should close connection with error', async () => {
@@ -222,7 +222,7 @@ describe('A socket channel', () => {
222222

223223
server.error();
224224

225-
await expect(channel.publish('foo')).rejects.toThrowError('Connection has been closed, reason');
225+
await expect(channel.publish('foo')).rejects.toThrow('Connection has been closed, reason');
226226
await expect(logger.error).toHaveBeenCalledWith('Connection error.');
227227
});
228228
});

test/evaluator.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ describe('An evaluator', () => {
169169

170170
const promise = evaluator.evaluate(expression);
171171

172-
await expect(promise).rejects.toThrowError(new EvaluationError(response));
172+
await expect(promise).rejects.toThrow(EvaluationError);
173+
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
173174
});
174175

175176
test.each([
@@ -216,7 +217,8 @@ describe('An evaluator', () => {
216217

217218
const promise = evaluator.evaluate(expression);
218219

219-
await expect(promise).rejects.toThrowError(new ExpressionError(response));
220+
await expect(promise).rejects.toThrow(ExpressionError);
221+
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
220222
},
221223
);
222224

@@ -280,7 +282,8 @@ describe('An evaluator', () => {
280282

281283
const promise = evaluator.evaluate(expression);
282284

283-
await expect(promise).rejects.toThrowError(new EvaluationError(response));
285+
await expect(promise).rejects.toThrow(EvaluationError);
286+
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
284287
});
285288
});
286289

test/schemas/contextSchemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('The token schema', () => {
1010
tokenScopeSchema.validate(value);
1111
}
1212

13-
expect(validate).not.toThrowError(Error);
13+
expect(validate).not.toThrow(Error);
1414
});
1515

1616
test('should not allow values other than the defined', () => {

test/schemas/ecommerceSchemas.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('The product details schema', () => {
5151
productDetails.validate(value);
5252
}
5353

54-
expect(validate).not.toThrowError(Error);
54+
expect(validate).not.toThrow(Error);
5555
});
5656

5757
test.each([
@@ -157,7 +157,7 @@ describe('The cart item schema', () => {
157157
cartItem.validate(value);
158158
}
159159

160-
expect(validate).not.toThrowError(Error);
160+
expect(validate).not.toThrow(Error);
161161
});
162162

163163
test.each([
@@ -304,7 +304,7 @@ describe('The cart schema', () => {
304304
cart.validate(value);
305305
}
306306

307-
expect(validate).not.toThrowError(Error);
307+
expect(validate).not.toThrow(Error);
308308
});
309309

310310
test.each([
@@ -508,7 +508,7 @@ describe('The order item schema', () => {
508508
orderItem.validate(value);
509509
}
510510

511-
expect(validate).not.toThrowError(Error);
511+
expect(validate).not.toThrow(Error);
512512
});
513513

514514
test.each([
@@ -680,7 +680,7 @@ describe('The order schema', () => {
680680
order.validate(value);
681681
}
682682

683-
expect(validate).not.toThrowError(Error);
683+
expect(validate).not.toThrow(Error);
684684
});
685685

686686
test.each([

test/schemas/evaluationSchemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('The evaluation option schema', () => {
1818
optionsSchema.validate(value);
1919
}
2020

21-
expect(validate).not.toThrowError(Error);
21+
expect(validate).not.toThrow(Error);
2222
});
2323

2424
test.each([

test/schemas/eventSchemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('The "cartModified" payload schema', () => {
4949

5050
test('should not allow %s', () => {
5151
function validate(): void {
52-
expect((): void => cartModified.validate({})).not.toThrowError(Error);
52+
expect((): void => cartModified.validate({})).not.toThrow(Error);
5353
}
5454

5555
expect(validate).toThrow(Error);

test/schemas/operationSchemas.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('An add operation schema', () => {
4444
addOperation.validate({path: 'foo', value: value});
4545
}
4646

47-
expect(validate).not.toThrowError(Error);
47+
expect(validate).not.toThrow(Error);
4848
});
4949

5050
test.each([
@@ -98,7 +98,7 @@ describe('A set operation schema', () => {
9898
setOperation.validate({path: 'foo', value: value});
9999
}
100100

101-
expect(validate).not.toThrowError(Error);
101+
expect(validate).not.toThrow(Error);
102102
});
103103

104104
test.each([
@@ -152,7 +152,7 @@ describe('A combine operation schema', () => {
152152
combineOperation.validate({path: 'foo', value: value});
153153
}
154154

155-
expect(validate).not.toThrowError(Error);
155+
expect(validate).not.toThrow(Error);
156156
});
157157

158158
test.each([
@@ -201,7 +201,7 @@ describe('A merge operation schema', () => {
201201
mergeOperation.validate({path: 'foo', value: value});
202202
}
203203

204-
expect(validate).not.toThrowError(Error);
204+
expect(validate).not.toThrow(Error);
205205
});
206206

207207
test.each([
@@ -251,7 +251,7 @@ describe('An increment operation schema', () => {
251251
incrementOperation.validate({path: 'foo', value: value});
252252
}
253253

254-
expect(validate).not.toThrowError(Error);
254+
expect(validate).not.toThrow(Error);
255255
});
256256

257257
test.each([
@@ -290,7 +290,7 @@ describe('A decrement operation schema', () => {
290290
decrementOperation.validate({path: 'foo', value: value});
291291
}
292292

293-
expect(validate).not.toThrowError(Error);
293+
expect(validate).not.toThrow(Error);
294294
});
295295

296296
test.each([

test/schemas/sdkFacadeSchemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('The SDK facade configuration schema', () => {
2323
configurationSchema.validate(value);
2424
}
2525

26-
expect(validate).not.toThrowError(Error);
26+
expect(validate).not.toThrow(Error);
2727
});
2828

2929
test.each([

test/schemas/sdkSchemas.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('The event metadata schema', () => {
1616
eventMetadataSchema.validate(value);
1717
}
1818

19-
expect(validate).not.toThrowError(Error);
19+
expect(validate).not.toThrow(Error);
2020
});
2121

2222
test.each([
@@ -91,7 +91,7 @@ describe('The SDK configuration schema', () => {
9191
configurationSchema.validate(value);
9292
}
9393

94-
expect(validate).not.toThrowError(Error);
94+
expect(validate).not.toThrow(Error);
9595
});
9696

9797
test.each([

test/schemas/tokenSchema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('The token schema', () => {
3636
tokenSchema.validate(value);
3737
}
3838

39-
expect(validate).not.toThrowError(Error);
39+
expect(validate).not.toThrow(Error);
4040
});
4141

4242
test.each([

test/schemas/userSchema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('The user profile schema', () => {
9898
userProfileSchema.validate(value);
9999
}
100100

101-
expect(validate).not.toThrowError(Error);
101+
expect(validate).not.toThrow(Error);
102102
});
103103

104104
test.each([

test/sdk.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ describe('A SDK', () => {
4141

4242
test('should validate the specified configuration', () => {
4343
expect(() => Sdk.init('' as unknown as Configuration))
44-
.toThrowError('The configuration must be a key-value map.');
44+
.toThrow('The configuration must be a key-value map.');
4545

4646
expect(() => Sdk.init({} as Configuration))
47-
.toThrowError('Invalid configuration');
47+
.toThrow('Invalid configuration');
4848
});
4949

5050
test('should be initialized with the specified app ID', () => {

test/tracker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('A tracker', () => {
215215
sinceTime: 0,
216216
};
217217

218-
await expect(tracker.track(event)).rejects.toThrowError('The tracker is suspended.');
218+
await expect(tracker.track(event)).rejects.toThrow('The tracker is suspended.');
219219

220220
tracker.unsuspend();
221221

test/validation/arrayType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('An array type', () => {
2828
type.validate(value);
2929
}
3030

31-
expect(validate).not.toThrowError(Error);
31+
expect(validate).not.toThrow(Error);
3232
});
3333

3434
test.each([

test/validation/booleanType.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ describe('A boolean type', () => {
2121
test('should allow boolean values', () => {
2222
const type = new BooleanType();
2323

24-
expect((): void => type.validate(true)).not.toThrowError(Error);
25-
expect((): void => type.validate(false)).not.toThrowError(Error);
24+
expect((): void => type.validate(true)).not.toThrow(Error);
25+
expect((): void => type.validate(false)).not.toThrow(Error);
2626
});
2727

2828
test.each([

test/validation/jsonType.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('A JSON array type', () => {
2727
schema.validate(value);
2828
}
2929

30-
expect(validate).not.toThrowError(Error);
30+
expect(validate).not.toThrow(Error);
3131
});
3232

3333
test.each([
@@ -81,7 +81,7 @@ describe('A JSON object type', () => {
8181
schema.validate(value);
8282
}
8383

84-
expect(validate).not.toThrowError(Error);
84+
expect(validate).not.toThrow(Error);
8585
});
8686

8787
test.each([
@@ -137,7 +137,7 @@ describe('A JSON primitive type', () => {
137137
new JsonPrimitiveType().validate(value);
138138
}
139139

140-
expect(validate).not.toThrowError(Error);
140+
expect(validate).not.toThrow(Error);
141141
});
142142

143143
test.each([
@@ -189,7 +189,7 @@ describe('A JSON value type', () => {
189189
new JsonType().validate(value);
190190
}
191191

192-
expect(validate).not.toThrowError(Error);
192+
expect(validate).not.toThrow(Error);
193193
});
194194

195195
test.each([

test/validation/nullType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('A null type', () => {
2121
test('should allow a null value', () => {
2222
const type = new NullType();
2323

24-
expect((): void => type.validate(null)).not.toThrowError(Error);
24+
expect((): void => type.validate(null)).not.toThrow(Error);
2525
});
2626

2727
test.each([

test/validation/numberType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('A number type', () => {
2828
type.validate(value);
2929
}
3030

31-
expect(validate).not.toThrowError(Error);
31+
expect(validate).not.toThrow(Error);
3232
});
3333

3434
test.each([

test/validation/objectType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('An object type', () => {
5151
type.validate(value);
5252
}
5353

54-
expect(validate).not.toThrowError(Error);
54+
expect(validate).not.toThrow(Error);
5555
});
5656

5757
test.each([

test/validation/stringType.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('A string type', () => {
4646
new StringType({format: format}).validate(value);
4747
}
4848

49-
expect(validate).not.toThrowError(Error);
49+
expect(validate).not.toThrow(Error);
5050
});
5151

5252
test.each([
@@ -101,7 +101,7 @@ describe('A string type', () => {
101101
type.validate(value);
102102
}
103103

104-
expect(validate).not.toThrowError(Error);
104+
expect(validate).not.toThrow(Error);
105105
});
106106

107107
test.each([

test/validation/unionType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('An union type', () => {
2929
new UnionType(new StringType(), new NumberType()).validate(value);
3030
}
3131

32-
expect(validate).not.toThrowError(Error);
32+
expect(validate).not.toThrow(Error);
3333
});
3434

3535
test.each([

0 commit comments

Comments
 (0)