Import the StoreModule.forRoot in the TestBed configuration when testing components or services that inject store.

Reducing state is synchronous, so mocking out the store isn't required.

You can refer the example here:
https://github.com/KtreeOpenSource/AngularExamples/tree/master/ngrxDemo

Step:1

Getting data from the store

Plain text
1.src/app/components/user-component/user-component.component.ts
JavaScript
1import { Component, OnInit } from '@angular/core';
2import { Store } from '@ngrx/store';
3import * as fromStore from '../../store/reducers/index';
4@Component({
5 selector: 'app-user-component',
6 templateUrl: './user-component.component.html',
7 styleUrls: ['./user-component.component.css']
8})
9export class UserComponentComponent implements OnInit {
10 public users = [];
11 constructor(public store: Store<fromStore.State>) { }
12 ngOnInit() {
13 this.store.select('user').subscribe(res => {
14 this.users = res.users;
15 });
16 }
17 getUsersFromSelectors() {
18 this.store.select(fromStore.getUserName).subscribe(res => {
19 console.log(res);
20 });
21 }
22}

Step:2

Importing the StoreModule.forRoot in TestBed configuration

Plain text
1.src/app/components/user-component/user-component.component.spec.ts
JavaScript
1import { StoreModule, Store } from '@ngrx/store';
2import * as fromRoot from '../../store/reducers/index';
3beforeEach(async(() => {
4 TestBed.configureTestingModule({
5 declarations: [UserComponentComponent],
6 imports: [
7 HttpClientModule,
8 StoreModule.forRoot({
9 ...fromRoot.reducers
10 })
11 ],
12 })
13 .compileComponents();
14}));

Step:3

Create store in the spec file

Plain text
1.src/app/components/user-component/user-component.component.spec.ts
JavaScript
1describe('UserComponentComponent', () => {
2 let component: UserComponentComponent;
3 let fixture: ComponentFixture<UserComponentComponent>;
4 let store: Store<fromRoot.State>;
5 beforeEach(async(() => {
6 TestBed.configureTestingModule({
7 declarations: [UserComponentComponent],
8 imports: [
9 HttpClientModule,
10 StoreModule.forRoot({
11 ...fromRoot.reducers
12 })
13 ],
14 })
15 .compileComponents();
16 }));
17 beforeEach(() => {
18 fixture = TestBed.createComponent(UserComponentComponent);
19 component = fixture.componentInstance;
20 store = TestBed.get(Store);
21 fixture.detectChanges();
22 });
23 it('should create', () => {
24 expect(component).toBeTruthy();
25 });
26});

Step:4

Testing the data exists in the store or not by dispatching the data to the store

Plain text
1.src/app/components/user-component/user-component.component.spec.ts
JavaScript
1it('should check users exists or not in init', () => {
2 const users = [{
3 'id': 1,
4 'userName': 'test1',
5 'email': 'test1@gmail.com'
6 }, {
7 'id': 2,
8 'userName': 'test2',
9 'email': 'test@gmail.com'
10 }];
11 store.dispatch(new UserActions.LoadUsers(users));
12 component.ngOnInit();
13 expect(component.users).toEqual(users);
14});