title: Angular unit testing router events
body: <p>I'm trying to mock router.events.subscribe() but it's not working. I tried to provide and event but I get an error: TypeError: Cannot read properties of undefined (reading 'root'). How can I do it?
  TS code:</p>
  <pre><code>ngOnInit(): void {
          this.router.events.subscribe(event =&gt; {
              this.splitRoutes();
          });
      }
  
      private splitRoutes() {
          const routes = this.router.url.toString().split('/');
              }
          }
      }
  </code></pre>
  <p>spec.ts:</p>
  <pre><code>beforeEach(async () =&gt; {
      await TestBed.configureTestingModule({
        imports: [],
        providers: [{
          provide: Router,
          useValue: {
            url: '/non-pdp/phases/8',
            events: of(
              new NavigationEnd(0, 'http://localhost:4200/#/non-pdp/phases/8', 'http://localhost:4200/#/non-pdp/phases/8')),
            navigate: jasmine.createSpy('navigate')
          }],
        })
      .compileComponents();
  });
  </code></pre>