2017-10-18 73 views
1

我最近升級我的角度的應用程序,其中涉及升級的角度包:單元測試終極版供電角應用

  • 所有@角/ *包從4.0.0 =>4.4.5
  • 的@ angular-終極版/商店包從6.1.0 =>6.5.7

在角4.0.0與NgRedux 6.1.0,這用來工作:

store = new NgRedux<IAppState>(null); 
store.configureStore(reducerConfig, undefined); 
// etc. 

但顯然,他們做了NgReduxabstract。因此,我的單元測試會失敗,以下異常: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一個終極版商店嗎?

+0

看看在[**中博客**](https://medium.com/@aravindfz/unit-testing-of-ngrx-store-in-angular-app-d0935c8d8d1b) – Aravind

回答

0

我能夠通過更換NgReduxRootStore來解決這個問題:

// without zone 
let store = new NgRedux<IAppState>(null); 

// with zone 
let store = new RootStore<IAppState>(new NgZone({enableLongStackTrace: true})); 

這工作,因爲RootStore是從抽象NgReduxinheriting,如在其回購:

// 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. 
}