Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度单元测试:无法读取属性';订阅';未定义的问题_Angular_Angular Unit Test - Fatal编程技术网

Angular 角度单元测试:无法读取属性';订阅';未定义的问题

Angular 角度单元测试:无法读取属性';订阅';未定义的问题,angular,angular-unit-test,Angular,Angular Unit Test,我正在尝试为我的代码编写单元测试。 组件 import {Component, Input, OnInit} from '@angular/core'; import {MainStorageService} from '@globals/storage/services/main-storage.service'; import {getSystemState, getWebcastState} from '@globals/store/main-reducer'; import {Webca

我正在尝试为我的代码编写单元测试。 组件

import {Component, Input, OnInit} from '@angular/core';
import {MainStorageService} from '@globals/storage/services/main-storage.service';
import {getSystemState, getWebcastState} from '@globals/store/main-reducer';
import {WebcastHelper} from '@webcast/webcast.helper';
import {DeviceInfoService} from '@core/services/device-info.service';


@Component({
    selector: 'app-presentation',
    templateUrl: 'presentation.component.html',
    styleUrls: ['presentation.component.scss']
})
export class PresentationComponent implements OnInit {

    assetPath: string;
    fileName: string;
    @Input() footerIsHigh: boolean;

    constructor(private store: MainStorageService,
                private device: DeviceInfoService) {
    }

    ngOnInit() {
        this.device.initInstance();
        this.device.destroyInstance();
        this.store.get(getSystemState).subscribe(appState => {
            this.fileName = appState.activeSlide.filename;
        });
        this.store.get(getWebcastState).subscribe(webcastData => {
            this.assetPath = WebcastHelper.generateAssetPathForSlides(webcastData);
        });
    }
}
规格

import { async, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { PresentationComponent } from './presentation.component';
import { MainStorageService } from '@globals/storage/services/main-storage.service';
import { DeviceInfoService } from '@core/services/device-info.service';
import { of } from 'rxjs';

const mockStore = {
  get() {
    return of({})
  }
}
const mockdevice = {
  initInstance() {},
  destroyInstance() {}
}
describe('PresentationComponent', () => {
  let component: PresentationComponent;
  let fixture: ComponentFixture<PresentationComponent>;
  let store: MainStorageService;
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ PresentationComponent ],
      providers: [ { provide: MainStorageService, useValue: mockStore}, {provide: DeviceInfoService, useValue: mockdevice}]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(PresentationComponent);
    component = fixture.componentInstance;
     store = TestBed.get(MainStorageService);
    // fixture.detectChanges();
  });


  it('should get file name and asset path', fakeAsync(() => {
    const mockWebcastData: any = {webcast: {company_id: 900, id: 300}, language: 'en', assetsDomain: 'https://testDomain.com'};
    const mockSystemData: any = {activeSlide: {fileName: 'logo.png'}};
    spyOn(store, 'get').and.returnValues(of(mockSystemData),of(mockWebcastData));
    component.ngOnInit();
    fixture.detectChanges();
    expect(component.fileName).toEqual('logo.png');
  }));
});
   TypeError: Cannot read property 'subscribe' of undefined
            at PresentationComponent../src/app/shared/desktop-presentation-area/components/presentation/presentation.component.ts.PresentationComponent.ngOnInit (src/app/shared/desktop-presentation-area/components/presentation/presentation.component.ts:26:39)