I'm trying to mock one of Typeorm module function in Jest and I want to do it in cleanest possible way. What I managed to create that works:
jest.mock("typeorm", () => ({
__esModule: true,
getCustomRepository: jest.fn(),
PrimaryGeneratedColumn: jest.fn(),
Column: jest.fn(),
CreateDateColumn: jest.fn(),
UpdateDateColumn: jest.fn(),
Entity: jest.fn(),
EntityRepository: jest.fn(),
Repository: jest.fn(),
}));
But I want to mock only getCustomReposity and when I leave mock only for that function:
jest.mock("typeorm", () => ({
__esModule: true,
getCustomRepository: jest.fn(),
}));
Tests don't even run, because entity and repository use some decorators and classes from Typeorm. I also tried to generate mocks for whole module:
jest.mock("typeorm", () => jest.createMockFromModule("typeorm"));
I got errors for generated mock decorators:
TypeError: decorator is not a function
2 |
3 | @Entity({ name: "users" })
> 4 | export class User {
Is there an way to create such mock in cleaner way than I did?