2017-10-18 5 views
1

が、私は最近、アップグレード関与私の角度アプリの角のパッケージアップグレード:4.0.0からユニットテストReduxの給電角度のApp

角度@
  • すべて/ *パッケージを=>4.4.5
  • @ angular-これが機能するために使用NgRedux 6.1.0と角度4.0.06.1.0 =>6.5.7

からReduxの/ストア・パッケージ:

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

しかし明らかに、彼らはクラスabstractを作成しました。したがって、私のユニットテストは、以下の例外で失敗します:

class MockRedux extends NgRedux<any> { 
    constructor() { 
    super(null); 
    } 
    dispatch =() => undefined; 
} 

はしかし、これはすべての抽象を実装していないため、失敗しました:Cannot create an instance of the abstract class 'NgRedux'.

Testing Redux - Testing Simple Actionsに提案されたように、私はカスタム嘲笑クラスを使用して、私のテストを修正しようとしましたこのようなエラーが発生したメンバー:

[ts] Non-abstract class 'MockRedux' does not implement inherited abstract member 'configureSubStore' from class 'NgRedux<any>'.

だから疑問が生じる:どのように私はきちんと私の角度スペック内NgReduxとReduxのストアを欺くのですか?

+0

は顔をしていますこの[**媒体ブログ**](https://medium.com/@aravindfz/unit-testing-of-ngrx-store-in-angular-app-d0935c8d8d1b) – Aravind

答えて

0

私はRootStoreNgReduxを置き換えることによって、それを解決することができました:

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

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

そのレポに見られるようRootStoreは、抽象NgReduxクラスからinheritingあるので、これは動作します:

// 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. 
} 
関連する問題