Skip to content

Commit

Permalink
test: add more tests for unexpected function calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jan 2, 2024
1 parent 20aebdd commit 1d912ec
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/dwait.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ describe("dwait Tests", () => {
new RangeError(`Property ${NUMBER} does not exists on undefined.`)
);
});

test("should throw on calling null or undefined DeferredPromise", async () => {
const nullPromise = dwait(null);
const undefinedPromise = dwait(undefined);
// @ts-expect-error Is is necessary for test to call it even tho it will throw
await expect(nullPromise()).rejects.toEqual(
new TypeError(
`null is not a function, unexpected call to null passing (nothing) as arguments.`
)
);
// @ts-expect-error Is is necessary for test to call it even tho it will throw
await expect(undefinedPromise()).rejects.toEqual(
new TypeError(
`undefined is not a function, unexpected call to undefined passing (nothing) as arguments.`
)
);
});

test("should throw on calling strings wrapped in DeferredPromise", async () => {
const strPromise = dwait(OK);
// @ts-expect-error Is is necessary for test to call it even tho it will throw
await expect(strPromise()).rejects.toEqual(
new TypeError(
`OK is not a function, unexpected call to OK passing (nothing) as arguments.`
)
);
});
});

describe("isDeferredPromise Tests", () => {
Expand Down

0 comments on commit 1d912ec

Please sign in to comment.