Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. @Injectable()
  2. export class SharedService {
  3. private _subject = new Subject<any>();
  4.  
  5. constructor() { }
  6.  
  7. shared_new_event(event) {
  8. this._subject.next(event);
  9. }
  10.  
  11. get emit_shared_event() {
  12. return this._subject.asObservable();
  13. }
  14. }
  15.  
  16. constructor( private shared_service: SharedService) { }
  17.  
  18. ngAfterViewInit() {
  19. this.shared_service.emit_shared_event.forEach(e => this.getDonationAmount(e));
  20. }
  21.  
  22. onclick_donate_amount($event) {
  23. this.shared_service.shared_new_event($event);
  24. }
  25.  
  26. describe('Shared Service', () => {
  27. let service: SharedService;
  28. let component: DonationComponent;
  29.  
  30. beforeEach(() => {
  31. service = new SharedService();
  32. });
  33.  
  34. it('should emit a new event ', () => {
  35. spyOn(service, 'shared_new_event').and.returnValue(Observable.of(40));
  36. });
  37.  
  38. component.ngAfterViewInit();
  39.  
  40. expect(component.onclick_donate_amount).toBe(40);
  41. });
  42.  
  43. Cannot read property 'ngAfterViewInit' of undefined
Add Comment
Please, Sign In to add comment