Guest User

Untitled

a guest
Nov 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. **Component:**
  2.  
  3. ngOnInit(){
  4.  
  5. this.globalFunctions.resulTest.subscribe(
  6. (value) => {
  7.  
  8. this.test = value;
  9.  
  10. });
  11.  
  12. }
  13.  
  14. **Service:**
  15.  
  16. public resulTest = new Subject<any>();
  17.  
  18. sendResult(result) {
  19. this.resulTest.next(result);
  20. }
  21.  
  22.  
  23. **specFile:**
  24. it('should test if the subsriber is active', () => {
  25. spyOn(globalFunctions, 'sendResult');
  26. spyOn(globalFunctions.resulTest, 'next');
  27.  
  28.  
  29. globalFunctions.sendResult('Test');
  30.  
  31.  
  32. expect(globalFunctions.sendResult).toHaveBeenCalled();
  33. expect(globalFunctions.resulTest.next).toHaveBeenCalled();
  34. expect(component.test).toEqual('test');
  35.  
  36. });
Add Comment
Please, Sign In to add comment