-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into conventional-comments
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { checkIsResponseError } from './checkIsResponseError'; | ||
import { IResponseError } from '../types'; | ||
|
||
describe('checkIsResponseError', () => { | ||
it('should return true for a valid IResponseError object', () => { | ||
const error: IResponseError = { | ||
error: 'Something went wrong', | ||
message: 'An error occurred', | ||
statusCode: 500, | ||
}; | ||
|
||
const result = checkIsResponseError(error); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false for null', () => { | ||
const result = checkIsResponseError(null); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false for undefined', () => { | ||
const result = checkIsResponseError(undefined); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false for a non-object value', () => { | ||
const result = checkIsResponseError('This is a string'); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if the object is missing the "error" property', () => { | ||
const error = { | ||
message: 'An error occurred', | ||
statusCode: 500, | ||
}; | ||
|
||
const result = checkIsResponseError(error); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if the object is missing the "message" property', () => { | ||
const error = { | ||
error: 'Something went wrong', | ||
statusCode: 500, | ||
}; | ||
|
||
const result = checkIsResponseError(error); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if the object is missing the "statusCode" property', () => { | ||
const error = { | ||
error: 'Something went wrong', | ||
message: 'An error occurred', | ||
}; | ||
|
||
const result = checkIsResponseError(error); | ||
expect(result).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IResponseError } from '../types'; | ||
|
||
/** | ||
* Validate (type-guard) that an error response matches our IResponseError interface. | ||
*/ | ||
export const checkIsResponseError = (err: unknown): err is IResponseError => { | ||
return !!err && typeof err === 'object' && 'error' in err && 'message' in err && 'statusCode' in err; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './checkIsResponseError'; | ||
export * from './env'; |