This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { IAppState } from '../model'; | |
| import { UserActions } from './actions'; | |
| export const initialState = { userData: null, loading: false }; | |
| export function UserReducer( | |
| state: IAppState = initialState, | |
| action: UserActions | |
| ): IAppState { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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’; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| beforeEach(() => TestBed.configureTestingModule({ | |
| imports: [HttpModule], | |
| providers: [ | |
| MockBackend, | |
| BaseRequestOptions, | |
| { | |
| provide: Http, | |
| useFactory: (backend, defaultOptions) => new Http(backend, defaultOptions), | |
| deps: [MockBackend, BaseRequestOptions] | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TestBed.configureTestingModule({ | |
| declarations: [ AppComponent ], | |
| schemas: [ NO_ERRORS_SCHEMA ] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('statistics should be sent', () => { | |
| const statisticsSpy = jest.spyOn(statisticsService, 'send'); | |
| service.handleGameData(expectedData); | |
| expect(statisticsSpy).toHaveBeenCalled(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('getGames should emits gameData', () => { | |
| service.getGames(); | |
| service.dataChange.subscribe((data) => { | |
| expect(data).toEqual(expectedData); | |
| }); | |
| const req = http.expectOne(service.gamesUrl); | |
| req.flush(expectedData); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should be created', () => { | |
| expect(service).toBeTruthy(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| afterEach(() => { | |
| http.verify(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| service = TestBed.get(GameService); | |
| statisticsService = TestBed.get(StatisticsService); | |
| http = TestBed.get(HttpTestingController); |