失败:无法解析MediaElementPlayer的所有参数:(?,?)

时间:2019-02-11 08:22:29

标签: angular

我正在尝试编写带有角度的单元测试。我的组件使用一个JQuery插件“ MedialElementPlayer”。当我运行ng test时,出现上述错误。我的测试失败。声明MediaElementPlayer后,决定将其添加为提供程序。我不确定这是否是正确的方法。

spect.ts file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { MediaElementComponent } from './media-element.component';

declare var MediaElementPlayer:any;


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

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MediaElementComponent],
      providers: [ MediaElementPlayer ]
    })
    .compileComponents();
  }));

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

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

ts file
import { Component, AfterViewInit, Input} from '@angular/core';
declare var MediaElementPlayer:any;

@Component({
  selector: 'media-element',
  templateUrl: './media-element.component.html',
  styleUrls: ['./media-element.component.scss']
})
export class MediaElementComponent implements AfterViewInit{
  @Input() source: string;
  @Input() id: string;

  constructor() {}

  ngAfterViewInit(): void {
    let player = new MediaElementPlayer(this.id,{ 
      alwaysShowControls: true,
      renderers: ['native_hls', 'html5', 'flash_hls', 'flash_video', 'flash_audio'],
      features: ['playpause'],
      audioVolume: 'horizontal',
      framesPerSecond: 25,
      audioWidth: 30,
      audioHeight: 30,
    
    });
    
    player.src= this.source;
  }
}

0 个答案:

没有答案