我使用的是角度为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: (?).有人能帮我找出我需要的参数吗?
发布于 2017-04-16 09:16:14
删除" providers : NgRedux“,因为如果您已经在使用NgReduxModule,则不需要向提供程序添加NgReduxModule。
https://stackoverflow.com/questions/43435599
复制相似问题