{"action":"closed","issue":{"url":"https://api.github.com/repos/angular/angular/issues/20942","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/20942/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/20942/comments","events_url":"https://api.github.com/repos/angular/angular/issues/20942/events","html_url":"https://github.com/angular/angular/issues/20942","id":281074755,"number":20942,"title":"Unit testing router events","user":{"login":"phsims","id":3962814,"avatar_url":"https://avatars1.githubusercontent.com/u/3962814?v=4","gravatar_id":"","url":"https://api.github.com/users/phsims","html_url":"https://github.com/phsims","followers_url":"https://api.github.com/users/phsims/followers","following_url":"https://api.github.com/users/phsims/following{/other_user}","gists_url":"https://api.github.com/users/phsims/gists{/gist_id}","starred_url":"https://api.github.com/users/phsims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phsims/subscriptions","organizations_url":"https://api.github.com/users/phsims/orgs","repos_url":"https://api.github.com/users/phsims/repos","events_url":"https://api.github.com/users/phsims/events{/privacy}","received_events_url":"https://api.github.com/users/phsims/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-12-11T16:14:02Z","updated_at":"2017-12-11T23:12:14Z","closed_at":"2017-12-11T23:12:14Z","author_association":"NONE","body":"I have looked everywhere and tried asking on stack overflow but cant find a good answer for how to properly unit test router events.\r\n\r\nThis is the code I am trying to test \r\n```\r\n    router.events.subscribe(event => {\r\n      if (event instanceof NavigationStart) {\r\n        this.isLoading = true;\r\n      } else if (event instanceof NavigationEnd || event instanceof NavigationCancel) {\r\n        this.isLoading = false;\r\n      } else if (event instanceof NavigationError) {\r\n        this.isLoading = false;\r\n        // console.error('effect error: ', error);\r\n      }\r\n    });\r\n```\r\n\r\nI have managed to get the stub working to some extent but so far I am not able to test multiple events from it\r\n\r\n```\r\n  class MockRouter {\r\n    navigate = jasmine.createSpy('navigate');\r\n    start = new NavigationStart(0, '/home');\r\n    end = new NavigationEnd(1, '/home', '/dashboard');\r\n    events = new Observable(observer => {\r\n      observer.next(this.start), isLoading = true, \r\n      observer.next(this.end), isLoading = false;\r\n      observer.complete();\r\n    });  \r\n  }\r\n```\r\n\r\nAny help would be much appriciated"}}
{"actor":{"display_login":"jasonaden"}}