title: Angular karma testing: TypeError: Cannot read property 'path' of null
body: <p>I am trying run some tests on Angular Karma on an angular component to determine the route.</p>
  
  <p>The component is structured like this</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { ActivatedRoute, Router } from '@angular/router';
  
  @Component({
    selector: 'app-basic-form',
    templateUrl: './basic-form.component.html',
    styleUrls: ['./basic-form.component.less'],
  })
  export class BasicFormComponent implements OnInit { 
    constructor(
      public activatedRoute: ActivatedRoute,
    ) {}
  
    ngOnInit() {
      if(this.activatedRoute.snapshot.routeConfig.path === 'basic-form/:date'){ // route with date
       let date = this.route.snapshot.paramMap.get('date'); // get the date
     } else {
      // no worries, just use the latest date, and this component can be used on multiple routes  
     }
   }
  </code></pre>
  
  <p>In my test file I have </p>
  
  <pre><code>import { async, ComponentFixture, TestBed } from '@angular/core/testing';
  import { RouterTestingModule } from '@angular/router/testing';
  import { ReactiveFormsModule, FormsModule } from '@angular/forms';
  import { BasicFormComponent } from './basic-form.component';
  
  
  describe('BasicFormComponent', () =&gt; {
    let component: BasicFormComponent;
    let fixture: ComponentFixture&lt;BasicFormComponent&gt;;
  
    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [ BasicFormComponent ],
        imports: [DemoMaterialModule, ReactiveFormsModule, FormsModule, HttpClientTestingModule,  RouterTestingModule.withRoutes([])],
        schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
        providers: [
        ]
  
      })
      .compileComponents();
    }));
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(BasicFormComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
  
    it('should create', () =&gt; {
      expect(component.activatedRoute.snapshot.routeConfig.path).toBeTruthy(); // why is this not working?
    });
  
  });
  </code></pre>
  
  <p>The errors I am getting is </p>
  
  <blockquote>
    <p>BasicFormComponent should create TypeError: Cannot read property
    'path' of null TypeError: Cannot read property 'snapshot' of undefined</p>
  </blockquote>
  
  <p>Why won't it import the activatedRoute module? </p>
  
  <p>I am trying to get my head wrapped testing, which seems to be a dark art. </p>
  
  <p>Any guidance will be appreciated.  </p>