Implement bun:test
support
#283
Replies: 3 comments
-
Hi @ceopaludetto, Thank you :) Although I haven't personally used Automock with Bun, it's good to know that it can :) Consider it as follows: import { beforeAll, describe, expect, it } from "bun:test";
import { TestBed, Mocked } from "@automock/bun";
import { EntityManager } from "@mikro-orm/postgresql";
import { UserService } from "~/components";
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();
});
}); What do you think? |
Beta Was this translation helpful? Give feedback.
-
Yeah I've suggested using |
Beta Was this translation helpful? Give feedback.
-
@ceopaludetto would you like to create a PR for this one? |
Beta Was this translation helpful? Give feedback.
-
Is there an existing issue for this?
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: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 onimport { jest } from 'bun:test';
instead ofglobal.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
Beta Was this translation helpful? Give feedback.
All reactions