Angular 9, Jasmine: "Error: unreachable" when doing unit test of a service

Viewed 1214

My problem is similar to Jasmine Angular 9 test failing because 'unreachable' stack trace at injectableDefOrInjectorDefFactory, but the solution there did not work for me.

Here is my .spec.ts file:

import { TestBed } from '@angular/core/testing';

import { DataService } from './data.service';
import { AngularFirestore } from '@angular/fire/firestore';
import { DataServiceMock, FirestoreStub } from './mock.data.service';

describe('DataService', () => {

  let service: DataService;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        { provide: DataService, useClass: DataServiceMock },
        { provide: AngularFirestore, useClass: FirestoreStub },
      ]
    }).compileComponents();
    service = TestBed.get(DataService);
    service.loadData();
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  it('should get have 2 products in its data', () => {
    expect(service.getData()).toEqual([
      {
        name: 'Camomile',
        description: 'Camomile oil',
        uses: ['topical', 'ingest'],
        benefits: ['headache', 'anxiety'],
      },
      {
        name: 'Cardamom',
        description: 'oil from the cardamom seed',
        uses: ['surface cleaning'],
        benefits: ['joint pain', 'hygiene'],
      }
    ]);
  });
});

For the "DataService > should be created", I get

Error: unreachable
    at injectableDefOrInjectorDefFactory (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:17298:1)
    at providerToFactory (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:17398:1)

Any help with figuring this out would be appreciated. If you need to see other code, let me know. Thanks much!

0 Answers
Related