aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-types/bun-test.d.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-11 19:14:34 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-11 19:14:34 -0700
commitcbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch)
tree43a00501f3cde495967e116f0b660777051551f8 /packages/bun-types/bun-test.d.ts
parent1f900cff453700b19bca2acadfe26da4468c1282 (diff)
parent34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff)
downloadbun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.gz
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.zst
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.zip
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
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,