Модульное тестирование Angular9: возможно ли MOCK Parse.initialize и по-прежнему иметь надежные тесты? - PullRequest
0 голосов
/ 16 июня 2020

Я хочу протестировать компонент, как мне это сделать с помощью функции Parse.initialize (appId, url) внутри моего Angular Service?
Это часть инициализации:

Parse.initialize('MY_APP_ID', 'JS_KEY');
Parse.serverURL = 'https://parseapi.back4app.com/';

Это моя тестовая часть:

describe('StateComponent', () => {
  let component: StateComponent;
  let fixture: ComponentFixture<StateComponent>;
  let service: TrayStateService;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [StateComponent],
      providers: [
        TrayStateService,
        { provide: NbDialogService, useValue: {} },
        { provide: NbToastrService, useValue: {} },
        ChangeDetectorRef,
        AuthSessionQuery,
        {
          provide: 'env',
          useValue: environment
        }
      ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA]
    }).compileComponents();
    service = TestBed.inject(TrayStateService);
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(StateComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should verify that immediate function works properly', fakeAsync(() => {
      spyOn(service, 'getAll').and.returnValue(of(MockedDataResponseArray));
      component.ngOnInit();
      tick(10);
  }));

Это ошибка, которую я получаю:

Error: You need to call Parse.initialize before using Parse.
...