我最近升级了我的角度应用程序的角度包,其中包括升级:
4.0.0
=>的所有@ angular / *包4.4.5
6.1.0
=>的@ angular-redux / store包6.5.7
在带有NgRedux 4.0.0
的角度6.1.0
中,过去常常有效:
store = new NgRedux<IAppState>(null);
store.configureStore(reducerConfig, undefined);
// etc.
但显然,他们制作了NgRedux
班abstract
。因此,我的单元测试将失败,并出现以下异常:Cannot create an instance of the abstract class 'NgRedux'.
我尝试使用Testing Redux - Testing Simple Actions上建议的自定义模拟类来修复我的测试:
class MockRedux extends NgRedux<any> {
constructor() {
super(null);
}
dispatch = () => undefined;
}
然而,由于未实现所有具有以下错误的抽象成员,因此失败:
[ts] Non-abstract class 'MockRedux' does not implement inherited abstract member 'configureSubStore' from class 'NgRedux<any>'.
所以问题出现了:如何在我的角度规格中使用NgRedux正确模拟redux商店?
答案 0 :(得分:0)
我可以将RootStore
替换为// without zone
let store = new NgRedux<IAppState>(null);
// with zone
let store = new RootStore<IAppState>(new NgZone({enableLongStackTrace: true}));
:
RootStore
这是有效的,因为NgRedux
来自抽象// store/src/components/root-store.ts
export class RootStore<RootState> extends NgRedux<RootState> {
private _store: Store<RootState>;
private _store$: BehaviorSubject<RootState>;
constructor(private ngZone: NgZone) {
super();
// etc.
}
//etc.
}
类的inheriting ,如其回购中所示:
DATE