Тестирование веток жасминовое угловое - PullRequest
0 голосов
/ 04 июня 2018

Я хочу проверить следующую функцию:

     ngOnInit() {
        this.hmDataService.loadData().subscribe((data) => {
          this.description= data.description;
          this.date= data.date;
          const restoredID= this.localStorage.getItem('key');
          if (restoredID) {
            this.type = restoredID.toString();
            this.selectedMenu= this.option.filter((rf: any) => {
              return rf.value === restoredID;
            })[0];
          }
          this.createTable(this.id, this.data, this.type);
        });
  }

Мне нужно это для тестового покрытия, которое ожидает от меня, чтобы проверить ветви.

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

    import { ChartComponent } from './chart.component';

    describe('ChartComponent', () => {
      let component: ChartComponent;
      let fixture: ComponentFixture<ChartComponent>;

      beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [ ChartComponent ]
        })
        .compileComponents();
      }));

      beforeEach(() => {
        fixture = TestBed.createComponent(ChartComponent);
        component = fixture.componentInstance;

      });

      it('should create', () => {
        expect(component).toBeTruthy();
      });
    it('should create table after page refresh', fakeAsync(() => {
      const restoredID = 'porsche';
      const spy = spyOn(component, 'createTableStructure');
      fixture.detectChanges();
      expect(component.selectedPaper.value).toEqual('porsche');
      expect(spy).toHaveBeenCalledTimes(1);
      }));
     });

Как я могу проверить это вправильно?Мне нужно проверить ветку, и моя переменная restoreID - это переменная функции, а не глобальная.Текущий тест не работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...