-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add async mutation support (#217)
Co-authored-by: Paul Brachmann <[email protected]> Co-authored-by: Terris Linenbach <[email protected]>
- Loading branch information
1 parent
de24bbc
commit b7f34ac
Showing
3 changed files
with
32 additions
and
2 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,23 @@ | ||
import { ensurePromise, isPromise } from './ensure-promise'; | ||
|
||
describe('isPromise', () => { | ||
it('should return true for a Promise', () => { | ||
expect(isPromise(Promise.resolve())).toBe(true); | ||
}); | ||
|
||
it('should return false for everything else', () => { | ||
expect(isPromise('not a Promise')).toBe(false); | ||
expect(isPromise({ then: 'not a function' })).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('ensurePromise', () => { | ||
it('should return the passed Promise', () => { | ||
const promise = Promise.resolve(); | ||
expect(ensurePromise(promise)).toBe(promise); | ||
}); | ||
|
||
it('should return everything else wrapped in a promise', () => { | ||
expect(isPromise(ensurePromise('not a Promise'))).toBe(true); | ||
}); | ||
}); |
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,6 @@ | ||
/** Returns true if `maybePromise` is a Promise. */ | ||
export const isPromise = <T>(maybePromise: T | Promise<T>): maybePromise is Promise<T> => | ||
Boolean(typeof (maybePromise as any)?.then === 'function'); | ||
|
||
export const ensurePromise = <T>(maybePromise: T | Promise<T>) => | ||
isPromise(maybePromise) ? maybePromise : Promise.resolve(maybePromise); |