簡體   English   中英

Angular 2 Jasmine錯誤:無法解析NgRedux的所有參數

[英]Angular 2 Jasmine error: Can't resolve all parameters for NgRedux

我正在使用ngRedux 2使用ngRedux

我正在嘗試測試一個使用ngRedux的簡單組件:

import { Component, OnInit } from '@angular/core';
import { NgRedux, select } from 'ng2-redux';
import { CustomerProfileModel, rootReducer } from '../common/customerProfileReducer';

@Component({
  selector: 'app-profile-details',
  templateUrl: './profile-details.component.html',
  styleUrls: ['./profile-details.component.css']
})
export class ProfileDetailsComponent implements OnInit {

  customerUIData: object;

  constructor(
    private ngRedux: NgRedux<Map<string, any>>) {
    this.ngRedux.subscribe(() => {
      this.getDataFromStore()
    })
  }

  ngOnInit() { this.getDataFromStore()}

  getDataFromStore() {
    var store = this.ngRedux.getState();
    this.customerUIData = store;
  }

}

我的單元測試如下:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgRedux, select, NgReduxModule } from 'ng2-redux';
import { ProfileDetailsComponent } from './profile-details.component';
import { CustomerProfileModel, rootReducer } from '../common/customerProfileReducer';

describe('ProfileDetailsComponent', () => {
  let component: ProfileDetailsComponent;
  let fixture: ComponentFixture<ProfileDetailsComponent>;
  let ngRedux: NgRedux<CustomerProfileModel>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ProfileDetailsComponent],
      providers: [NgRedux],
      imports:[NgReduxModule]
    })
      .compileComponents();

  }));

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

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

Redux商店如下:

export interface CustomerProfileModel {
    customerData: {
        ....
    };
}

export const CUSTPROFILE_INITIAL_STATE: CustomerProfileModel = {
    customerData: {
        ....
    }
};

export function rootReducer(state: CustomerProfileModel, action) {
    switch (action.type) {
        case 'GET_CUSTOMER_PROFILE_SUCCESS':
          return { customerData: action.customerData };
    }
    return state;
}

我收到如下錯誤

Failed: Can't resolve all parameters for NgRedux: (?).

誰能幫我弄清楚我需要輸入哪些參數?

刪除“提供者:[NgRedux]”,因為如果您已經在使用NgReduxModule,則不需要將NgRedux添加到您的提供程序中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM