diff options
author | 2023-06-13 22:28:31 -0700 | |
---|---|---|
committer | 2023-06-13 22:28:31 -0700 | |
commit | a1bb79f4403bbff0ae8a25acffcf079ce6d40f3b (patch) | |
tree | e67257cab565c70795dd2a57b29161a4ec95f74e | |
parent | 171ba6327d995bdde473e1b723f449b3e88d1c14 (diff) | |
download | bun-a1bb79f4403bbff0ae8a25acffcf079ce6d40f3b.tar.gz bun-a1bb79f4403bbff0ae8a25acffcf079ce6d40f3b.tar.zst bun-a1bb79f4403bbff0ae8a25acffcf079ce6d40f3b.zip |
`mock` type changes (#3305)
* Update mock types and set bun-types@latest in bun init
* Remove mockfn methods from toplevel mock
* Remove comments
-rw-r--r-- | packages/bun-types/bun-test.d.ts | 34 | ||||
-rw-r--r-- | packages/bun-types/tests/mocks.test-d.ts | 16 | ||||
-rw-r--r-- | src/cli/init_command.zig | 8 |
3 files changed, 17 insertions, 41 deletions
diff --git a/packages/bun-types/bun-test.d.ts b/packages/bun-types/bun-test.d.ts index bf89b808d..d6bc062c0 100644 --- a/packages/bun-types/bun-test.d.ts +++ b/packages/bun-types/bun-test.d.ts @@ -27,43 +27,11 @@ declare module "bun:test" { export const mock: { <T extends AnyFunction>(Function: T): Mock<T>; - - mockClear(): typeof mock; - mockReset(): typeof mock; - mockRestore(): void; - mockReturnValue<T extends JestMock.FunctionLike = JestMock.UnknownFunction>( - value: ReturnType<T>, - ): JestMock.MockInstance<T>; - mockReturnValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: ReturnType<T>, - ): JestMock.MockInstance<T>; - mockResolvedValue< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.ResolveType<T>, - ): JestMock.MockInstance<T>; - mockResolvedValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.ResolveType<T>, - ): JestMock.MockInstance<T>; - mockRejectedValue< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.RejectType<T>, - ): JestMock.MockInstance<T>; - mockRejectedValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.RejectType<T>, - ): JestMock.MockInstance<T>; }; interface Jest { restoreAllMocks(): void; - fn<T extends AnyFunction>(func: T): Mock<T>; + fn<T extends AnyFunction>(func?: T): Mock<T>; } export const jest: Jest; export namespace jest { diff --git a/packages/bun-types/tests/mocks.test-d.ts b/packages/bun-types/tests/mocks.test-d.ts index f4fe47d4f..9bb8a9070 100644 --- a/packages/bun-types/tests/mocks.test-d.ts +++ b/packages/bun-types/tests/mocks.test-d.ts @@ -14,4 +14,18 @@ declare var arg2: arg2; arg2.mock.calls[0]; mock; -type _arg3 = jest.Mock<() => number>; +// @ts-expect-error +jest.fn<() => Promise<string>>().mockReturnValue("asdf"); +// @ts-expect-error +jest.fn<() => string>().mockReturnValue(24); +jest.fn<() => string>().mockReturnValue("24"); + +jest.fn<() => Promise<string>>().mockResolvedValue("asdf"); +// @ts-expect-error +jest.fn<() => string>().mockResolvedValue(24); +// @ts-expect-error +jest.fn<() => string>().mockResolvedValue("24"); + +jest.fn().mockClear(); +jest.fn().mockReset(); +jest.fn().mockRejectedValueOnce(new Error()); diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index bc8867368..c7f566836 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -300,13 +300,7 @@ pub const InitCommand = struct { if (needs_dev_dependencies) { var dev_dependencies = fields.object.get("devDependencies") orelse js_ast.Expr.init(js_ast.E.Object, js_ast.E.Object{}, logger.Loc.Empty); - const version = comptime brk: { - var base = Global.version; - base.patch = 0; - break :brk base; - }; - - try dev_dependencies.data.e_object.putString(alloc, "bun-types", comptime std.fmt.comptimePrint("^{any}", .{version.fmt("")})); + try dev_dependencies.data.e_object.putString(alloc, "bun-types", "latest"); try fields.object.put(alloc, "devDependencies", dev_dependencies); } |