Skip to content

Instantly share code, notes, and snippets.

import { IAppState } from '../model';
import { UserActions } from './actions';
export const initialState = { userData: null, loading: false };
export function UserReducer(
state: IAppState = initialState,
action: UserActions
): IAppState {
import { Injectable } from ‘@angular/core’;
import { NgRedux } from ‘@angular-redux/store’;
import { AuthService } from ‘auth’;
import { IAppState } from ‘../model’;
@Injectable()
export class UserActions {
constructor(private ngRedux: NgRedux) {}
static GET_USER_REQUESTED = ‘GET_USER_REQUESTED’;
beforeEach(() => TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backend, defaultOptions) => new Http(backend, defaultOptions),
deps: [MockBackend, BaseRequestOptions]
},
TestBed.configureTestingModule({
declarations: [ AppComponent ],
schemas: [ NO_ERRORS_SCHEMA ]
})
it('statistics should be sent', () => {
const statisticsSpy = jest.spyOn(statisticsService, 'send');
service.handleGameData(expectedData);
expect(statisticsSpy).toHaveBeenCalled();
});
it('getGames should emits gameData', () => {
service.getGames();
service.dataChange.subscribe((data) => {
expect(data).toEqual(expectedData);
});
const req = http.expectOne(service.gamesUrl);
req.flush(expectedData);
it('should have made one request to GET data from expected URL', () => {
service.makeResponse().subscribe((data) => {
expect(data).toEqual(expectedData);
});
const req = http.expectOne(service.gamesUrl);
expect(req.request.method).toEqual('GET');
req.flush(expectedData);
it('should be created', () => {
expect(service).toBeTruthy();
});
afterEach(() => {
http.verify();
});
service = TestBed.get(GameService);
statisticsService = TestBed.get(StatisticsService);
http = TestBed.get(HttpTestingController);