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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there an existing issue for this?
Is your feature request related to a problem? Please describe it
Since bun supports
jest.fnI was able to use@automock/jestin 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/bunwhich is a copy of@automock/jestbut 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