-
-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
Since bun supports jest.fn I was able to use @automock/jest in my test by supplying jest in global. Working example:
import type { Mock } from "bun:test";
import { beforeAll, describe, expect, it, jest } from "bun:test";
import { TestBed } from "@automock/jest";
import { EntityManager } from "@mikro-orm/postgresql";
import { UserService } from "~/components";
(global as any).jest = jest;
type Mocked<T> = {
[P in keyof T]: T[P] extends (...args: infer A) => infer R ? Mock<(...args: A) => R> : T[P];
};
describe("UserService", () => {
let userService!: UserService;
let entityManager!: Mocked<EntityManager>;
beforeAll(() => {
const { unit, unitRef } = TestBed.create(UserService).compile();
userService = unit;
entityManager = unitRef.get(EntityManager);
});
it("#findAll", () => {
entityManager.findAndCount.mockResolvedValue([[], 0]);
expect(userService.findAll({ limit: 10, offset: 0 })).resolves.toEqual([[], 0]);
expect(entityManager.findAndCount).toHaveBeenCalled();
});
});Bun also doesn't have Mocked type by default, so I've created one instead.
Describe the solution you'd like
Provide a @automock/bun which is a copy of @automock/jest but relying on import { jest } from 'bun:test'; instead of global.jest. Also reexport the type Mocked for convenience(I dunno if this type should be recursive).
What is the motivation / use case for changing the behavior?
This library is awesome and bun test runner is fast af. Both combined make NestJS tests enjoyable
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request