title: Getting error after running the jasmine test case :- TypeError: this.snackBarRef.dismiss is not a function
body: <p>I am getting an error after running the test case. Below is my ts file.</p>
  
  <pre class="lang-js prettyprint-override"><code>    import { Component, OnInit, Inject} from '@angular/core';
      import { MAT_SNACK_BAR_DATA } from '@angular/material';
      import { MatSnackBarRef } from '@angular/material';
  
      @Component({
          selector: 'Message',
          templateUrl: './Message.component.html',
          styleUrls: ['./Message.component.scss'],
      })
      export class MessageComponent implements OnInit {
          constructor(
              @Inject(MAT_SNACK_BAR_DATA) public data: any,
              public snackBarRef: MatSnackBarRef&lt;MessageComponent&gt;
          ) {}
  
          ngOnInit() {}
  
          dismiss(): void {
              this.snackBarRef.dismiss();
          }
      }
  </code></pre>
  
  <p>I am getting the following error - TypeError: this.snackBarRef.dismiss is not a function</p>
  
  <p>I have spied on the function as below - </p>
  
  <pre><code>describe('MessageComponent', () =&gt; {
  let component: MessageComponent;
  let fixture;
  
  beforeEach(() =&gt; {
      TestBed.configureTestingModule({
          providers: [{ provide: MAT_SNACK_BAR_DATA, useValue: {} }, { provide: MatSnackBarRef, useValue: {} }],
          declarations: [MessageComponent],
      });
  
      fixture = TestBed.createComponent(MessageComponent);
      component = fixture.componentInstance;
      spyOn(component, 'dismiss').and.callThrough();
  });
  it('should call dismiss function', () =&gt; {
      component.dismiss();
      expect(component.dismiss).toHaveBeenCalled();
  });
  });
  </code></pre>
  
  <p>I need the solution to fix this error.</p>