UNPKG

1.58 kBJavaScriptView Raw
1import { Actions } from '@ngrx/effects';
2import { defer } from 'rxjs';
3
4/**
5 * @description
6 * Creates mock actions provider.
7 *
8 * @param factoryOrSource Actions' source or source creation function
9 *
10 * @usageNotes
11 *
12 * **With `TestBed.configureTestingModule`**
13 *
14 * ```ts
15 * describe('Books Effects', () => {
16 * let actions$: Observable<any>;
17 * let effects: BooksEffects;
18 *
19 * beforeEach(() => {
20 * TestBed.configureTestingModule({
21 * providers: [
22 * provideMockActions(() => actions$),
23 * BooksEffects,
24 * ],
25 * });
26 *
27 * actions$ = TestBed.inject(Actions);
28 * effects = TestBed.inject(BooksEffects);
29 * });
30 * });
31 * ```
32 *
33 * **With `Injector.create`**
34 *
35 * ```ts
36 * describe('Counter Effects', () => {
37 * let injector: Injector;
38 * let actions$: Observable<any>;
39 * let effects: CounterEffects;
40 *
41 * beforeEach(() => {
42 * injector = Injector.create({
43 * providers: [
44 * provideMockActions(() => actions$),
45 * CounterEffects,
46 * ],
47 * });
48 *
49 * actions$ = injector.get(Actions);
50 * effects = injector.get(CounterEffects);
51 * });
52 * });
53 * ```
54 */
55function provideMockActions(factoryOrSource) {
56 return {
57 provide: Actions,
58 useFactory: () => {
59 if (typeof factoryOrSource === 'function') {
60 return new Actions(defer(factoryOrSource));
61 }
62 return new Actions(factoryOrSource);
63 },
64 deps: [],
65 };
66}
67
68/**
69 * Generated bundle index. Do not edit.
70 */
71
72export { provideMockActions };