-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace throwIfNull for throwIfNil
- Loading branch information
1 parent
910cab5
commit aa94bb8
Showing
6 changed files
with
33 additions
and
28 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { parseResult } from './parse-result'; | ||
export { Transaction, withTransaction } from './with-transaction'; | ||
export { throwIfNull } from './throw-if-null'; | ||
export { throwIfNil } from './throw-if-nil'; | ||
export { throwIfDuplicated } from './throw-if-duplicated'; |
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,5 @@ | ||
export async function throwIfNil<T>(ifNilError: Error, promise: Promise<T | null | undefined>): Promise<T> { | ||
const result = await promise; | ||
if (result === null || result === undefined) throw ifNilError; | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
import { throwIfNil } from '../src/throw-if-nil'; | ||
|
||
describe('throwIfNil()', () => { | ||
const ifNilError = Error('value is null or undefined'); | ||
|
||
test('should return the value when it is not null', async () => { | ||
const input = Promise.resolve(42); | ||
const output = await throwIfNil(ifNilError, input); | ||
expect(output).toBe(42); | ||
}); | ||
|
||
test('should throw when the value is null', async () => { | ||
const input = Promise.resolve(null); | ||
await expect(throwIfNil(ifNilError, input)).rejects.toThrow(ifNilError); | ||
}); | ||
|
||
test('should throw when the value is undefined', async () => { | ||
const input = Promise.resolve(undefined); | ||
await expect(throwIfNil(ifNilError, input)).rejects.toThrow(ifNilError); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.