Skip to content

Commit

Permalink
test: simplify error expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
cjuega committed Nov 16, 2023
1 parent 123fa01 commit e1f3fd9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ describe('exampleAggregateCreator', () => {
clock.whenNowThenReturn(createdAt);
repository.whenSearchThenReturn(exampleAggregate);

let error;

try {
await handler.handle(command);
} catch (e) {
error = e;
} finally {
expect(error).toBeInstanceOf(ExampleAggregateAlreadyExists);
}
await expect(handler.handle(command)).rejects.toThrow(ExampleAggregateAlreadyExists);
});

it('should create a valid exampleAggregate', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ describe('inMemoryCommandBus', () => {
commandHandlersInformation = new CommandHandlersInformation([]),
commandBus = new InMemoryCommandBus(commandHandlersInformation);

let error;

try {
await commandBus.dispatch(unhandledCommand);
} catch (e) {
error = e;
} finally {
expect(error).toBeInstanceOf(CommandNotRegisteredError);
expect((error as Error).message).toBe("The command <UnhandledCommand> hasn't a command handler associated");
}
await expect(commandBus.dispatch(unhandledCommand)).rejects.toThrow(CommandNotRegisteredError);
});

// eslint-disable-next-line jest/prefer-expect-assertions,jest/expect-expect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ describe('inMemoryQueryBus', () => {
queryHandlersInformation = new QueryHandlersInformation([]),
queryBus = new InMemoryQueryBus(queryHandlersInformation);

let error;

try {
await queryBus.ask(unhandledQuery);
} catch (e) {
error = e;
} finally {
expect(error).toBeInstanceOf(QueryNotRegisteredError);
expect((error as Error).message).toBe("The query <UnhandledQuery> hasn't a query handler associated");
}
await expect(queryBus.ask(unhandledQuery)).rejects.toThrow(QueryNotRegisteredError);
});

// eslint-disable-next-line jest/prefer-expect-assertions,jest/expect-expect
Expand Down

0 comments on commit e1f3fd9

Please sign in to comment.