forked from PluralFlux/PluralFlux
adjusted importHelper to properly test throwing of aggregate error
This commit is contained in:
@@ -78,23 +78,23 @@ describe('importHelper', () => {
|
||||
|
||||
test('if addFullMember returns nothing, return correct enum', async () => {
|
||||
memberHelper.addFullMember.mockResolvedValue();
|
||||
await expect(importHelper.pluralKitImport(authorId, attachmentUrl)).rejects.toThrow(([], enums.err.NO_MEMBERS_IMPORTED));
|
||||
const promise = importHelper.pluralKitImport(authorId, attachmentUrl);
|
||||
await expect(promise).rejects.toBeInstanceOf(AggregateError);
|
||||
await expect(promise).rejects.toMatchObject(AggregateError([], enums.err.NO_MEMBERS_IMPORTED));
|
||||
})
|
||||
|
||||
test('if addFullMember throws error, catch and return error', async () => {
|
||||
memberHelper.addFullMember.mockRejectedValue(new Error('error'));
|
||||
await expect(importHelper.pluralKitImport(authorId, attachmentUrl)).rejects.toThrow(([new Error('error')], enums.err.NO_MEMBERS_IMPORTED));
|
||||
})
|
||||
await expect(importHelper.pluralKitImport(authorId, attachmentUrl)).rejects.toMatchObject(new AggregateError(['error'], enums.err.NO_MEMBERS_IMPORTED));
|
||||
});
|
||||
|
||||
test('if addFullMember returns member but also contains error, return member and error', async () => {
|
||||
// Arrange
|
||||
const memberObj = {errors: ['error'], member: mockAddReturnMember};
|
||||
memberHelper.addFullMember.mockResolvedValue(memberObj);
|
||||
// Act & Assert
|
||||
await expect(importHelper.pluralKitImport(authorId, attachmentUrl)).rejects.toThrow((['error'], `Successfully added members: ${mockAddReturnMember.name}`));
|
||||
})
|
||||
|
||||
})
|
||||
await expect(importHelper.pluralKitImport(authorId, attachmentUrl)).rejects.toMatchObject(new AggregateError(['error'], `Successfully added members: ${mockAddReturnMember.name}`));
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// restore the spy created with spyOn
|
||||
|
||||
Reference in New Issue
Block a user