UNPKG

2.77 kBTypeScriptView Raw
1import { ExistingProvider, FactoryProvider, ValueProvider } from '@angular/core';
2import { MockStore } from './mock_store';
3import { MockSelector } from './mock_selector';
4export interface MockStoreConfig<T> {
5 initialState?: T;
6 selectors?: MockSelector[];
7}
8/**
9 * @description
10 * Creates mock store providers.
11 *
12 * @param config `MockStoreConfig<T>` to provide the values for `INITIAL_STATE` and `MOCK_SELECTORS` tokens.
13 * By default, `initialState` and `selectors` are not defined.
14 * @returns Mock store providers that can be used with both `TestBed.configureTestingModule` and `Injector.create`.
15 *
16 * @usageNotes
17 *
18 * **With `TestBed.configureTestingModule`**
19 *
20 * ```typescript
21 * describe('Books Component', () => {
22 * let store: MockStore;
23 *
24 * beforeEach(() => {
25 * TestBed.configureTestingModule({
26 * providers: [
27 * provideMockStore({
28 * initialState: { books: { entities: [] } },
29 * selectors: [
30 * { selector: selectAllBooks, value: ['Book 1', 'Book 2'] },
31 * { selector: selectVisibleBooks, value: ['Book 1'] },
32 * ],
33 * }),
34 * ],
35 * });
36 *
37 * store = TestBed.inject(MockStore);
38 * });
39 * });
40 * ```
41 *
42 * **With `Injector.create`**
43 *
44 * ```typescript
45 * describe('Counter Component', () => {
46 * let injector: Injector;
47 * let store: MockStore;
48 *
49 * beforeEach(() => {
50 * injector = Injector.create({
51 * providers: [
52 * provideMockStore({ initialState: { counter: 0 } }),
53 * ],
54 * });
55 * store = injector.get(MockStore);
56 * });
57 * });
58 * ```
59 */
60export declare function provideMockStore<T = any>(config?: MockStoreConfig<T>): (ValueProvider | ExistingProvider | FactoryProvider)[];
61/**
62 * @description
63 * Creates mock store with all necessary dependencies outside of the `TestBed`.
64 *
65 * @param config `MockStoreConfig<T>` to provide the values for `INITIAL_STATE` and `MOCK_SELECTORS` tokens.
66 * By default, `initialState` and `selectors` are not defined.
67 * @returns `MockStore<T>`
68 *
69 * @usageNotes
70 *
71 * ```typescript
72 * describe('Books Effects', () => {
73 * let store: MockStore;
74 *
75 * beforeEach(() => {
76 * store = getMockStore({
77 * initialState: { books: { entities: ['Book 1', 'Book 2', 'Book 3'] } },
78 * selectors: [
79 * { selector: selectAllBooks, value: ['Book 1', 'Book 2'] },
80 * { selector: selectVisibleBooks, value: ['Book 1'] },
81 * ],
82 * });
83 * });
84 * });
85 * ```
86 */
87export declare function getMockStore<T>(config?: MockStoreConfig<T>): MockStore<T>;
88export { MockReducerManager } from './mock_reducer_manager';
89export { MockState } from './mock_state';
90export { MockStore } from './mock_store';
91export { MockSelector } from './mock_selector';