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

时间:2017-09-22 08:44:30

标签: angular unit-testing typescript web karma-jasmine

请帮我解决这个问题。我已经尝试了很多东西,但没有解决,网上有很多东西,但没有得到解决方案。我的问题是我在组件构造函数中传递了一些类,现在它在krma测试中抛出了错误。

我的组件代码

setTimeout(function(){ insert Facebook pixel code here}, 3000);

我的规格     ----------------

`import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { NavbarSandbox } from '../../../navbar/sandbox/navbar.sandbox';
import { ServiceProviderResult } from '../../../shared/models/service-provider';

@Component({
  selector: 'ccw-nav-bar',
  templateUrl: './nav-bar.component.html',
  styleUrls: ['./nav-bar.component.scss']
})
export class NavBarComponent implements OnInit {
  serviceProviderList$: Observable<ServiceProviderResult[]>;
  constructor(public store: Store<any>, public navSandBox: NavbarSandbox) { }

  ngOnInit() {
    this.serviceProviderList$ = this.navSandBox.getServiceProviderListAPI(null);
  }

  changeCurrentServiceProviderChanged(selectedProviderResult: number): void {
    if (selectedProviderResult !== undefined) {
      this.navSandBox.setSelectedServiceProvider({ id: selectedProviderResult });
    }
  }

  // To get selected dropdown value
  getSelectedData(): void {
    this.navSandBox.getSelectedServiceProvider().subscribe((res) => { console.log(res); });
  }

}
`

但是在业力开始时 - 浏览器PhantomJS正在显示

应该创建NavBarComponent 失败:无法解析NavbarSandbox的所有参数:(?,?)。 错误:无法解析NavbarSandbox的所有参数:(?,?)。

navbarsandbox代码:

`import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { NavbarSandbox } from '../../sandbox/navbar.sandbox';
import { MenuBarComponent } from '../../components/menu-bar/menu-bar.component';
import { TitleBarComponent } from '../../components/title-bar/title-bar.component';
import { NavBarComponent } from './nav-bar.component';

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

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ NavBarComponent, MenuBarComponent, TitleBarComponent ],
      providers: [NavbarSandbox, Store]
    })
    .compileComponents();
  }));

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

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

0 个答案:

没有答案