![](/img/trans.png)
[英]Angular 2 / Jasmine / Karma error: Error: Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?). in config/karma-shim.js
[英]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.