Open
Description
Description
Constructor Injection fail in vitest/jest
Injected with instance ContainerInstance
import 'reflect-metadata';
//import {expect, test} from "vitest"
import {expect, test} from '@jest/globals';
import { Container, Inject, Service, ServiceOptions, Token } from 'typedi';
import { FlexEvent } from 'flex-tools';
@Service({
id:"app",
global:true,
eager:true
})
class App extends FlexEvent{
constructor(
@Inject(WORKSHOP)
public workshop:Workshop
){
super()
}
@Service({
id:"app",
global:true,
eager:true
})
class App extends FlexEvent{
constructor(
@Inject(WORKSHOP)
public workshop:Workshop
){
super()
// workshop === Injected with instance ContainerInstance
}
}
test("构造注入", () => {
let app = Container.get("app") as App
expect(app.workshop).toBeInstanceOf(Workshop)
})
Expected behavior
Injected with instance Workshop
Actual behavior
Injected with instance Workshop ContainerInstance