I’m currently build an app with IOC using inversify
and inversify-binding-decorators
, but when I create a test for the service that using @provide(Service)
it got error Cannot access 'Service' before initialization
My code look like this:
// src/services/userService.ts
import { provide } from 'inversify-binding-decorators';
@provide(UserService)
export class UserService {
public get(): User {
return {
id: 1,
name: 'test',
age: 15
}
}
}
// src/services/userService.test.ts
import { UserService } from './userService';
describe('UserService', () => {
let service: UserService;
beforeEach(() => {
service = new UserService();
});
describe('User GET Test', () => {
it(`Should return user data with name 'test'`, async () => {
const data = await service.get();
expect(data.name).toEqual('test');
});
});
});
// babel.config.json
{
"presets": [
["@babel/preset-env", { "targets": { "node": "current" } }],
["@babel/preset-typescript", { "allowDeclareFields": true }]
],
"plugins": [["@babel/plugin-proposal-decorators", { "legacy": true }]]
}
Is there any error with my code?
Thanks in advance