1- import { Provider } from '@angular/core' ;
1+ import { FactoryProvider } from '@angular/core' ;
22import { Actions } from '@ngrx/effects' ;
33import { defer , Observable } from 'rxjs' ;
44
5- export function provideMockActions ( source : Observable < any > ) : Provider ;
6- export function provideMockActions ( factory : ( ) => Observable < any > ) : Provider ;
5+ /**
6+ * @description
7+ * Creates mock actions provider.
8+ *
9+ * @param source Actions' source
10+ */
11+ export function provideMockActions ( source : Observable < any > ) : FactoryProvider ;
12+ /**
13+ * @description
14+ * Creates mock actions provider.
15+ *
16+ * @param factory Actions' source creation function
17+ *
18+ * @usageNotes
19+ *
20+ * **With `TestBed.configureTestingModule`**
21+ *
22+ * ```ts
23+ * describe('Books Effects', () => {
24+ * let actions$: Observable<any>;
25+ * let effects: BooksEffects;
26+ *
27+ * beforeEach(() => {
28+ * TestBed.configureTestingModule({
29+ * providers: [
30+ * provideMockActions(() => actions$),
31+ * BooksEffects,
32+ * ],
33+ * });
34+ *
35+ * actions$ = TestBed.inject(Actions);
36+ * effects = TestBed.inject(BooksEffects);
37+ * });
38+ * });
39+ * ```
40+ *
41+ * **With `Injector.create`**
42+ *
43+ * ```ts
44+ * describe('Counter Effects', () => {
45+ * let injector: Injector;
46+ * let actions$: Observable<any>;
47+ * let effects: CounterEffects;
48+ *
49+ * beforeEach(() => {
50+ * injector = Injector.create({
51+ * providers: [
52+ * provideMockActions(() => actions$),
53+ * CounterEffects,
54+ * ],
55+ * });
56+ *
57+ * actions$ = injector.get(Actions);
58+ * effects = injector.get(CounterEffects);
59+ * });
60+ * });
61+ * ```
62+ */
63+ export function provideMockActions (
64+ factory : ( ) => Observable < any >
65+ ) : FactoryProvider ;
766export function provideMockActions (
867 factoryOrSource : ( ( ) => Observable < any > ) | Observable < any >
9- ) : Provider {
68+ ) : FactoryProvider {
1069 return {
1170 provide : Actions ,
1271 useFactory : ( ) : Observable < any > => {
@@ -16,5 +75,6 @@ export function provideMockActions(
1675
1776 return new Actions ( factoryOrSource ) ;
1877 } ,
78+ deps : [ ] ,
1979 } ;
2080}
0 commit comments