Skip to content

Commit

Permalink
Fix error assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed Apr 17, 2020
1 parent 8d92a62 commit e6ade1d
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export type ExpressionErrorResponse = ErrorResponse & {
}

export class ExpressionError extends EvaluationError<ExpressionErrorResponse> {
constructor(response: ExpressionErrorResponse) {
public constructor(response: ExpressionErrorResponse) {
super(response);

Object.setPrototypeOf(this, ExpressionError.prototype);
Expand Down
2 changes: 1 addition & 1 deletion test/channel/guaranteedChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('A guaranteed channel', () => {
// Invalid acknowledge stamp
sandboxChannel.notify('pong_stamp');

await expect(promise).rejects.toThrowError('Maximum confirmation time reached.');
await expect(promise).rejects.toThrow('Maximum confirmation time reached.');
});

test('should stop waiting for confirmation if the channel is closed in the meanwhile', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/channel/queuedChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('A queued channel', () => {
};
const channel = new QueuedChannel(outputChannel, new CapacityRestrictedQueue(new InMemoryQueue('foo'), 1));

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

test('should fail to publish messages if the channel is closed', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/channel/socketChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('A socket channel', () => {

await channel.close();

await expect(channel.publish('bar')).rejects.toThrowError('Channel has been closed.');
await expect(channel.publish('bar')).rejects.toThrow('Channel has been closed.');
});

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

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

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

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

await expect(channel.close()).rejects.toThrowError('Maximum close timeout reached.');
await expect(channel.close()).rejects.toThrow('Maximum close timeout reached.');
});

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

server.error();

await expect(channel.publish('foo')).rejects.toThrowError('Connection has been closed, reason');
await expect(channel.publish('foo')).rejects.toThrow('Connection has been closed, reason');
await expect(logger.error).toHaveBeenCalledWith('Connection error.');
});
});
9 changes: 6 additions & 3 deletions test/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ describe('An evaluator', () => {

const promise = evaluator.evaluate(expression);

await expect(promise).rejects.toThrowError(new EvaluationError(response));
await expect(promise).rejects.toThrow(EvaluationError);
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
});

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

const promise = evaluator.evaluate(expression);

await expect(promise).rejects.toThrowError(new ExpressionError(response));
await expect(promise).rejects.toThrow(ExpressionError);
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
},
);

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

const promise = evaluator.evaluate(expression);

await expect(promise).rejects.toThrowError(new EvaluationError(response));
await expect(promise).rejects.toThrow(EvaluationError);
await expect(promise).rejects.toEqual(expect.objectContaining({response: response}));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/schemas/contextSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('The token schema', () => {
tokenScopeSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test('should not allow values other than the defined', () => {
Expand Down
10 changes: 5 additions & 5 deletions test/schemas/ecommerceSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('The product details schema', () => {
productDetails.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('The cart item schema', () => {
cartItem.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('The cart schema', () => {
cart.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('The order item schema', () => {
orderItem.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -680,7 +680,7 @@ describe('The order schema', () => {
order.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/evaluationSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('The evaluation option schema', () => {
optionsSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/eventSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('The "cartModified" payload schema', () => {

test('should not allow %s', () => {
function validate(): void {
expect((): void => cartModified.validate({})).not.toThrowError(Error);
expect((): void => cartModified.validate({})).not.toThrow(Error);
}

expect(validate).toThrow(Error);
Expand Down
12 changes: 6 additions & 6 deletions test/schemas/operationSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('An add operation schema', () => {
addOperation.validate({path: 'foo', value: value});
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

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

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

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

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

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

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

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

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

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

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/sdkFacadeSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('The SDK facade configuration schema', () => {
configurationSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
4 changes: 2 additions & 2 deletions test/schemas/sdkSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('The event metadata schema', () => {
eventMetadataSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('The SDK configuration schema', () => {
configurationSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/tokenSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('The token schema', () => {
tokenSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/userSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('The user profile schema', () => {
userProfileSchema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
4 changes: 2 additions & 2 deletions test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ describe('A SDK', () => {

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

expect(() => Sdk.init({} as Configuration))
.toThrowError('Invalid configuration');
.toThrow('Invalid configuration');
});

test('should be initialized with the specified app ID', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('A tracker', () => {
sinceTime: 0,
};

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

tracker.unsuspend();

Expand Down
2 changes: 1 addition & 1 deletion test/validation/arrayType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('An array type', () => {
type.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
4 changes: 2 additions & 2 deletions test/validation/booleanType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('A boolean type', () => {
test('should allow boolean values', () => {
const type = new BooleanType();

expect((): void => type.validate(true)).not.toThrowError(Error);
expect((): void => type.validate(false)).not.toThrowError(Error);
expect((): void => type.validate(true)).not.toThrow(Error);
expect((): void => type.validate(false)).not.toThrow(Error);
});

test.each([
Expand Down
8 changes: 4 additions & 4 deletions test/validation/jsonType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('A JSON array type', () => {
schema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('A JSON object type', () => {
schema.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('A JSON primitive type', () => {
new JsonPrimitiveType().validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('A JSON value type', () => {
new JsonType().validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/validation/nullType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('A null type', () => {
test('should allow a null value', () => {
const type = new NullType();

expect((): void => type.validate(null)).not.toThrowError(Error);
expect((): void => type.validate(null)).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/validation/numberType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('A number type', () => {
type.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/validation/objectType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('An object type', () => {
type.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
4 changes: 2 additions & 2 deletions test/validation/stringType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('A string type', () => {
new StringType({format: format}).validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('A string type', () => {
type.validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down
2 changes: 1 addition & 1 deletion test/validation/unionType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('An union type', () => {
new UnionType(new StringType(), new NumberType()).validate(value);
}

expect(validate).not.toThrowError(Error);
expect(validate).not.toThrow(Error);
});

test.each([
Expand Down

0 comments on commit e6ade1d

Please sign in to comment.