mock type changes (#3305)

* Update mock types and set bun-types@latest in bun init

* Remove mockfn methods from toplevel mock

* Remove comments
This commit is contained in:
Colin McDonnell
2023-06-13 22:28:31 -07:00
committed by GitHub
parent 171ba6327d
commit a1bb79f440
3 changed files with 17 additions and 41 deletions

View File

@@ -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 {

View File

@@ -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());

View File

@@ -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);
}