使用具有其他模块依赖性的Jest测试Sagas

时间:2018-01-06 11:06:57

标签: jest saga

我正在尝试测试一个内部引用具有RNFiresbase依赖关系的对象的传奇。以下是我的文件,AccountSaga导入AccountRepo,它依赖于RNFirebase,当我测试' Sign'来自AccountSaga的传奇我得到以下错误。在我的测试中导入AccountSaga时,测试在初始化时失败。

测试我的“登录”的正确方法是什么?佐贺?

item.details.rating

AccountRepo.js

 1 | import firebase from 'react-native-firebase';
      2 | import { ACCOUNT_PATH } from './constants';
      3 | 
      4 | const ACCOUNT_REF = firebase.firestore().collection(ACCOUNT_PATH);
      Error: RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.

AccountSaga.js

import firebase from 'react-native-firebase';
import { ACCOUNT_PATH } from './constants';

const ACCOUNT_REF = firebase.firestore().collection(ACCOUNT_PATH);

const AccountRepo = {

  getAccount(user){
    console.log('Getting account for user :'+user.uid);
    return ACCOUNT_REF.doc(user.uid).get().then(function(doc) {
      if (doc.exists) {
        return doc.data();
      } else {
        console.warn("No such document!");
        return null;
      }
    })
  }
}

AccountSaga.test.js

import { call, put, select , take, takeEvery} from 'redux-saga/effects';

import { SIGN_IN, SIGN_UP,SHOW_SIGN_UP, SIGNED_IN, ERROR } from '../action/types';
import { AccountRepo } from '../repo';


  function *signIn(action) {
    try{
      const {user} = action.payload;
      console.log('In *SIGN_IN saga for user '+JSON.stringify(user));
      const account = yield call(AccountRepo.getAccount, user);
      console.log('account is '+account);
      if(account) {
        yield put({type: SIGNED_IN, payload:account});
      } else {
        yield put({type: SHOW_SIGN_UP, payload:user});
      }
    } catch (error) {
      console.log('Error retrieving account '+error);
      yield put({type: ERROR,error});
    }
  }

export const AccountSagas = [
  takeEvery(SIGN_IN, signIn)
]

0 个答案:

没有答案