11import "@testing-library/jest-dom" ;
22import { render , screen } from "@testing-library/react" ;
3- import React from "react" ;
4- import { DIContextProvider } from "../di-context/di-context-provider" ;
5- import { useInjection } from "./useInjection" ;
3+ import { InjectionToken , InjectorStub } from "@universal-di/core" ;
4+ import { DIContainer } from "@universal-di/core/dist/src/di-container/di-container.js" ;
65import {
76 afterEach ,
87 beforeEach ,
@@ -12,32 +11,19 @@ import {
1211 MockInstance ,
1312 vi ,
1413} from "vitest" ;
15- import { InjectionToken , Injector } from "@universal-di/core" ;
16-
17- class TestInjector {
18- private readonly value : any ;
19-
20- constructor ( value : any ) {
21- this . value = value ;
22- }
23-
24- get ( ) {
25- return this . value ;
26- }
27- }
28-
29- export const InjectorStub = TestInjector ;
14+ import { DIContextProvider } from "../di-context/di-context-provider" ;
15+ import { useInjection } from "./useInjection" ;
3016
3117describe ( "useInjection" , ( ) => {
32- const tokenStub = new InjectionToken < string > ( "TOKEN_STUB" ) ;
18+ const tokenStub = new InjectionToken ( "TOKEN_STUB" ) ;
3319 const valueStub = "valueStub" ;
3420 const ComponentStub = ( ) => {
35- const injectedValue : string = useInjection ( tokenStub ) ;
21+ const injectedValue = useInjection ( tokenStub ) ;
3622
37- return < div > { injectedValue } </ div > ;
23+ return < div > { injectedValue as string } </ div > ;
3824 } ;
3925
40- let injector : Injector ;
26+ let injector : DIContainer ;
4127 let consoleErrorSpy : MockInstance ;
4228
4329 beforeEach ( ( ) => {
@@ -51,23 +37,22 @@ describe("useInjection", () => {
5137 } ) ;
5238
5339 it ( "renders children with provided injector value" , ( ) => {
54- injector = new InjectorStub ( valueStub ) as any ;
40+ injector = new InjectorStub ( valueStub ) ;
5541
5642 render (
5743 < DIContextProvider injector = { injector } >
5844 < ComponentStub />
5945 </ DIContextProvider >
6046 ) ;
6147
62- // @ts -ignore
6348 expect ( screen . getByText ( valueStub ) ) . toBeInTheDocument ( ) ;
6449 } ) ;
6550
6651 it ( "throws error for no context" , ( ) => {
67- injector = new InjectorStub ( valueStub ) as any ;
52+ injector = new InjectorStub ( valueStub ) ;
6853
6954 const renders = ( ) => render ( < ComponentStub /> ) ;
7055
71- expect ( renders ) . toThrowError ( "No DI context provided" ) ;
56+ expect ( renders ) . toThrowError ( "No di context provided" ) ;
7257 } ) ;
7358} ) ;
0 commit comments