aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-types/bun-test.d.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bun-types/bun-test.d.ts')
-rw-r--r--packages/bun-types/bun-test.d.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/bun-types/bun-test.d.ts b/packages/bun-types/bun-test.d.ts
index ba59966ad..5182f7e93 100644
--- a/packages/bun-types/bun-test.d.ts
+++ b/packages/bun-types/bun-test.d.ts
@@ -29,6 +29,36 @@ declare module "bun:test" {
<T extends AnyFunction>(Function: T): Mock<T>;
};
+ /**
+ * Control the system time used by:
+ * - `Date.now()`
+ * - `new Date()`
+ * - `Intl.DateTimeFormat().format()`
+ *
+ * In the future, we may add support for more functions, but we haven't done that yet.
+ *
+ * @param now The time to set the system time to. If not provided, the system time will be reset.
+ * @returns `this`
+ * @since v0.6.13
+ *
+ * ## Set Date to a specific time
+ *
+ * ```js
+ * import { setSystemTime } from 'bun:test';
+ *
+ * setSystemTime(new Date('2020-01-01T00:00:00.000Z'));
+ * console.log(new Date().toISOString()); // 2020-01-01T00:00:00.000Z
+ * ```
+ * ## Reset Date to the current time
+ *
+ * ```js
+ * import { setSystemTime } from 'bun:test';
+ *
+ * setSystemTime();
+ * ```
+ */
+ export function setSystemTime(now?: Date | number): ThisType<void>;
+
interface Jest {
restoreAllMocks(): void;
fn<T extends AnyFunction>(func?: T): Mock<T>;
@@ -425,6 +455,20 @@ declare module "bun:test" {
*/
not: Expect<unknown>;
/**
+ * Expects the value to be a promise that resolves.
+ *
+ * @example
+ * expect(Promise.resolve(1)).resolves.toBe(1);
+ */
+ resolves: Expect<unknown>;
+ /**
+ * Expects the value to be a promise that rejects.
+ *
+ * @example
+ * expect(Promise.reject("error")).rejects.toBe("error");
+ */
+ rejects: Expect<unknown>;
+ /**
* Asserts that a value equals what is expected.
*
* - For non-primitive values, like objects and arrays,