Skip to content

Commit

Permalink
fix: support for dwaiting constructor calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jan 1, 2024
1 parent a8f7638 commit 3821135
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dwait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function noop() {}
* @internal
*/
function dwaitInternal<T, Y>(
promise: Promise<T>,
promise: Promise<T> | T,
lhs?: Box<Y>
): DeferredPromise<T> {
const task = Promise.resolve(promise);
Expand Down Expand Up @@ -84,7 +84,7 @@ function dwaitInternal<T, Y>(
*
* @returns A {@link DeferredPromise} pointing to the target `Promise`
*/
function dwait<T>(promise: Promise<T>): DeferredPromise<T> {
function dwait<T>(promise: Promise<T> | T): DeferredPromise<T> {
return dwaitInternal(promise);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/dwait.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ describe("dwait Tests", () => {
const dwaitPromise = dwait(resolveMock()).toPromise();
await expect(dwaitPromise).resolves.toBe(OK);
});
test("should be able to wrap a constructor successfully", async () => {
const dwaitPromise = dwait(new TestClass(OK, NUMBER, OK));
await expect(dwaitPromise.await).resolves.toEqual(
expect.objectContaining({ foo: OK + OK })
);
});
});

0 comments on commit 3821135

Please sign in to comment.