title: angular Jasmine - cannot set property of undefined
body: <p>My component code:</p>
  
  <pre><code>public save() {
    this.gridService.gridCellUpdated = false;
  }
  </code></pre>
  
  <p>My Jasmine code</p>
  
  <pre><code>class GridServiceMock {
    public gridCellUpdated = false;
  }
  let gridService: GridService;
  beforeEach(
    async(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [ModalComponent, BsModalDirective],
        providers: [{ provide: GridService, use: GridServiceMock }]
      })
      .compileComponents();
    });
  );
  
  it('should save assets', () =&gt; {
    gridService = fixture.debugElement.injector.get(GridService);
    component.save();
    expect(gridService.gridCellUpdated).toBeFalsy();
  });
  </code></pre>
  
  <p>My error:</p>
  
  <pre><code>TypeError: Cannot set property 'gridCellUpdated' of undefined
  </code></pre>
  
  <p>Edit:
  Updated the code by following below solutions but still get the same error.</p>