1
- import { Component } from '@angular/core' ;
1
+ import { Component , EnvironmentInjector } from '@angular/core' ;
2
2
import { TestBed } from '@angular/core/testing' ;
3
3
import { jestMatcher } from '@test-helpers/rx-angular' ;
4
4
import { Observable , of , Subject , tap , timer } from 'rxjs' ;
@@ -104,6 +104,24 @@ describe(rxEffects, () => {
104
104
expect ( spyInternalOnCleanup ) . toHaveBeenCalled ( ) ;
105
105
expect ( spyOnCleanup ) . toHaveBeenCalled ( ) ;
106
106
} ) ;
107
+
108
+ describe ( 'without injection context' , ( ) => {
109
+ it ( 'should throw when invoked without injection context' , ( ) => {
110
+ const { rxEffects } = setUpWithoutInjectionContext ( ) ;
111
+ expect ( ( ) => rxEffects ( ( ) => { } , { } ) ) . toThrow (
112
+ / r x E f f e c t s \( \) c a n o n l y b e u s e d w i t h i n a n i n j e c t i o n c o n t e x t / ,
113
+ ) ;
114
+ } ) ;
115
+
116
+ it ( 'should be able to use a custom Injector' , ( ) => {
117
+ const { rxEffects } = setUpWithoutInjectionContext ( ) ;
118
+
119
+ const envInjector = TestBed . inject ( EnvironmentInjector ) ;
120
+
121
+ const effects = rxEffects ( ( ) => { } , { injector : envInjector } ) ;
122
+ expect ( effects ) . toBeDefined ( ) ;
123
+ } ) ;
124
+ } ) ;
107
125
} ) ;
108
126
109
127
function setupComponent ( setupFn ?: RxEffectsSetupFn ) {
@@ -123,3 +141,12 @@ function setupComponent(setupFn?: RxEffectsSetupFn) {
123
141
component : fixture . componentInstance ,
124
142
} ;
125
143
}
144
+
145
+ function setUpWithoutInjectionContext ( ) {
146
+ return {
147
+ rxEffects ( ...args : Parameters < typeof rxEffects > ) {
148
+ const effects = rxEffects ( ...args ) ;
149
+ return effects ;
150
+ } ,
151
+ } ;
152
+ }
0 commit comments