1
- import { Provider } from '@angular/core' ;
1
+ import { FactoryProvider } from '@angular/core' ;
2
2
import { Actions } from '@ngrx/effects' ;
3
3
import { defer , Observable } from 'rxjs' ;
4
4
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 ;
7
66
export function provideMockActions (
8
67
factoryOrSource : ( ( ) => Observable < any > ) | Observable < any >
9
- ) : Provider {
68
+ ) : FactoryProvider {
10
69
return {
11
70
provide : Actions ,
12
71
useFactory : ( ) : Observable < any > => {
@@ -16,5 +75,6 @@ export function provideMockActions(
16
75
17
76
return new Actions ( factoryOrSource ) ;
18
77
} ,
78
+ deps : [ ] ,
19
79
} ;
20
80
}
0 commit comments