-
Notifications
You must be signed in to change notification settings - Fork 287
Closed
Description
Versions
- sequelize: 5.19.2
- sequelize-typescript: 1.0.0
- typescript: 3.6.3
I'm submitting a ...
[ ] bug report
[X] feature request
Hi,
Do you have any idea, how should I mock Sequalize class in tests in this case?
I have repository
const mockGetRepository = {
findOne: jest.fn(),
};
import User from 'models/User';
jest.mock('components/DatabaseConnection', () => {
return {
__esModule: true,
default: {
addModels: (m: any) => {
return;
},
getRepository: () => mockGetRepository,
models: {User},
},
};
});
import models from 'models';
import UserRepository from 'repositories/UserRepository';
describe('UserRepository test', () => {
it('findById test - user exist', async (done) => {
mockGetRepository.findOne.mockImplementationOnce(() => {
return new models.User({id: 123});
});
const user = await UserRepository.findById(123);
expect(user).toEqual({id: 123});
done();
});
});
When I try to create a new instance of User I got an error like that
Model not initialized: User cannot be instantiated. "User" needs to be added to a Sequelize instance.
Do you have any idea, how can I fix this problem?
Metadata
Metadata
Assignees
Labels
No labels