I'm barely new with Unit Testing, and I'm stuck in this functionality.

```
onPreview(value: any): void {
    this.showLoading('Cargando PDF...');
    if (value) {
      this._restService.getDocument(value).subscribe(
        (restResult: any) => {

          this._dialog.open(DialogPreviewDocument, {
            data: restResult.data
          });
        },
        error => {
          Swal.fire({
            icon: 'error',
            title: 'Ocurrió un error al abrir este documento',
            confirmButtonColor: '#3085d6',
            confirmButtonText: 'Cerrar'
          }).then(r => {
          });
        }
      );
    }
  }

```

This are my Tests, the first one works well, but when I try to test when I receive an error from the service I received an error.

```
it('should call onPreview with error', (done => {
        spyOn(component, 'onPreview');
        let getDocument = spyOn(service, 'getDocument')
        spyOn(Swal, 'fire')
        component.onPreview("1614210817503");
        setTimeout(() =>{
            getDocument.and.throwError("Error")
            expect(service.getDocument).toHaveBeenCalled();
            expect(Swal.fire).toHaveBeenCalled()

        })
    }));

```

```
Error: Expected spy getDocument to have been called.
        at <Jasmine>
        at http://localhost:4200/_karma_webpack_/src/app/modules/home/components/dashboard-details/dashboard-details.component.spec.ts:468:41
        at ZoneDelegate.invokeTask (http://localhost:4200/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:399:1)
        at ProxyZoneSpec.push.QpwO.ProxyZoneSpec.onInvokeTask (http://localhost:4200/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:323:1)
    Error: Expected spy fire to have been called.
        at <Jasmine>
        at http://localhost:4200/_karma_webpack_/src/app/modules/home/components/dashboard-details/dashboard-details.component.spec.ts:469:31
        at ZoneDelegate.invokeTask (http://localhost:4200/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:399:1)
        at ProxyZoneSpec.push.QpwO.ProxyZoneSpec.onInvokeTask (http://localhost:4200/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:323:1)

```

If anyone can give a example or a explanation about what I'm doing wrong I would be grateful.
Thanks in advance