zoukankan      html  css  js  c++  java
  • [Redux-Observable && Unit testing] Testing the output of epics

    Epics can be unit-tested just like any other function in your application - they have a very specific set of inputs (the action$ stream) and the output is always an Observable. We can subscribe to this output Observable to assert that the actions going back into the Redux are the ones we expect.

    export function fetchUserEpic(action$) {
      return action$.ofType('FETCH_USER')
        .map(action => ({
          type: 'FETCH_USER_FULFILLED',
          payload: {
            name: 'Shane',
            user: action.payload
          }
        }))
    }
    import {Observable} from 'rxjs';
    import {ActionsObservable} from 'redux-observable';
    import {fetchUserEpic} from "./fetch-user-epic";
    it('should return correct actions', function () {
      const action$ = ActionsObservable.of({
        type: 'FETCH_USER',
        payload: 'shakyshane'
      });
    
      const output$ = fetchUserEpic(action$);
      output$.toArray().subscribe(actions => {
        expect(actions.length).toBe(1);
      });
    });
  • 相关阅读:
    hdu1159 LCS模板题
    RabbitMQ入门
    Dubbo
    SpringMVC
    MySQL的再理解
    ElasticSearch
    redis入门学习
    Swagger
    SSM整合
    MybatisPlus
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7683195.html
Copyright © 2011-2022 走看看