Skip to content

fix: Constructor Injection fail in vitest/jest #1084

Open
@zhangfisher

Description

@zhangfisher

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions