Skip to content

Commit

Permalink
chore: make test error mock content explicitly different
Browse files Browse the repository at this point in the history
  • Loading branch information
0.618 committed May 15, 2024
1 parent db73695 commit 63146cf
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ describe('test exception handler', () => {

it('error handler should print error', async () => {
const amplifyError = new AmplifyError('NotImplementedError', {
message: 'Test Not implemented',
details: 'Test Not implemented',
resolution: 'Test Not implemented',
message: 'Test Not implemented(message)',
details: 'Test Not implemented(details)',
resolution: 'Test Not implemented(resolution)',
});

await handleException(amplifyError);

expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`);
expect(printerMock.info).toHaveBeenCalledTimes(2);
expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`);
expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.resolution}`);
expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/');
expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack);
});

it('error handler should handle encountered errors gracefully', async () => {
const amplifyError = new AmplifyError('NotImplementedError', {
message: 'Test Not implemented',
details: 'Test Not implemented',
resolution: 'Test Not implemented',
message: 'Test Not implemented(message)',
details: 'Test Not implemented(details)',
resolution: 'Test Not implemented(resolution)',
});

reportErrorMock.mockRejectedValueOnce(new Error('MockTestError'));
await handleException(amplifyError);

expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`);
expect(printerMock.info).toHaveBeenCalledTimes(2);
expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`);
expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.resolution}`);
expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/');
expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack);
expect(printerMock.error).toHaveBeenCalledWith('Failed to report error: MockTestError');
Expand Down

0 comments on commit 63146cf

Please sign in to comment.