2024-07-19 22:12:29 +02:00
|
|
|
describe("toBeFulfilled", () => {
|
|
|
|
it("passes when promise is resolved", async () => {
|
|
|
|
const promise = Promise.resolve("resolved");
|
|
|
|
await promise;
|
|
|
|
await expect(promise).toBeFulfilled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when promise is rejected", async () => {
|
|
|
|
const promise = Promise.reject("rejected");
|
|
|
|
await promise.catch(() => {});
|
|
|
|
await expect(promise).toBeFulfilled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fails when promise is pending", async () => {
|
|
|
|
const promise = new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
await expect(promise).not.toBeFulfilled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is fulfilled within the given time limit", async () => {
|
|
|
|
const promise = new Promise((resolve) => setTimeout(resolve, 1));
|
2024-07-24 08:46:02 +02:00
|
|
|
await expect(promise).toBeFulfilled(25);
|
2024-07-19 22:12:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is not fulfilled within the given time limit", async () => {
|
2024-07-24 08:46:02 +02:00
|
|
|
const promise = new Promise(() => {});
|
2024-07-19 22:12:29 +02:00
|
|
|
await expect(promise).not.toBeFulfilled(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("toBeResolved", () => {
|
|
|
|
it("passes when promise is resolved", async () => {
|
|
|
|
const promise = Promise.resolve("resolved");
|
|
|
|
await promise;
|
|
|
|
await expect(promise).toBeResolved();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fails when promise is rejected", async () => {
|
|
|
|
const promise = Promise.reject("rejected");
|
|
|
|
await promise.catch(() => {});
|
|
|
|
await expect(promise).not.toBeResolved();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fails when promise is pending", async () => {
|
|
|
|
const promise = new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
await expect(promise).not.toBeResolved();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is resolved within the given time limit", async () => {
|
|
|
|
const promise = new Promise((resolve) => setTimeout(resolve, 1));
|
2024-07-24 08:46:02 +02:00
|
|
|
await expect(promise).toBeResolved(50);
|
2024-07-19 22:12:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is not resolved within the given time limit", async () => {
|
2024-07-24 08:46:02 +02:00
|
|
|
const promise = new Promise(() => {});
|
2024-07-19 22:12:29 +02:00
|
|
|
await expect(promise).not.toBeResolved(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("toBeRejected", () => {
|
|
|
|
it("fails when promise is resolved", async () => {
|
|
|
|
const promise = Promise.resolve("resolved");
|
|
|
|
await promise;
|
|
|
|
await expect(promise).not.toBeRejected();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when promise is rejected", async () => {
|
|
|
|
const promise = Promise.reject("rejected");
|
|
|
|
await promise.catch(() => {});
|
|
|
|
await expect(promise).toBeRejected();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("fails when promise is pending", async () => {
|
|
|
|
const promise = new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
await expect(promise).not.toBeRejected();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is resolved within the given time limit", async () => {
|
|
|
|
const promise = new Promise((_, reject) => setTimeout(reject, 1));
|
2024-07-24 08:46:02 +02:00
|
|
|
await expect(promise).toBeFulfilled(50);
|
2024-07-19 22:12:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("passes when the promise is not resolved within the given time limit", async () => {
|
2024-07-24 08:46:02 +02:00
|
|
|
const promise = new Promise(() => {});
|
2024-07-19 22:12:29 +02:00
|
|
|
await expect(promise).not.toBeFulfilled(1);
|
|
|
|
});
|
|
|
|
});
|