| /** |
| ****************************************************************************** |
| * Copyright © 2017-2018 PTA GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| ****************************************************************************** |
| */ |
| import { TestBed, async, inject } from '@angular/core/testing'; |
| import { Subscription } from 'rxjs/Subscription'; |
| |
| export abstract class AbstractMockObservableService { |
| protected _subscription: Subscription; |
| protected _fakeContent: any; |
| protected _fakeError: any; |
| |
| set error(err) { |
| this._fakeError = err; |
| } |
| |
| set content(data) { |
| this._fakeContent = data; |
| } |
| |
| get subscription(): Subscription { |
| return this._subscription; |
| } |
| |
| subscribe(next: Function, error?: Function, complete?: Function): Subscription { |
| this._subscription = new Subscription(); |
| //spyOn(this._subscription, 'unsubscribe'); |
| |
| if (next && this._fakeContent && !this._fakeError) { |
| next(this._fakeContent); |
| } |
| if (error && this._fakeError) { |
| error(this._fakeError); |
| } |
| if (complete) { |
| complete(); |
| } |
| return this._subscription; |
| } |
| } |