Stack Overflow Asked by mzafer on January 24, 2021
I am trying to test a saga that internally refers to an object with RNFiresbase
dependency.
Below are my files, the AccountSaga
imports AccountRepo
which has a dependency on RNFirebase
and when I test the ‘Sign’ saga from AccountSaga
I get the below error. The test fails at initialization itself when the AccountSaga
is imported in my test.
What is the right way to test my ‘SignIn’ Saga ?
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`.
AccountRepo.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.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)
]
AccountSaga.test.js
import {signIn} from '../../app/saga/AccountSagas';
import { SIGN_IN, SIGN_UP,SHOW_SIGN_UP, SIGNED_IN, ERROR } from '../../app/action/types';
import { AccountRepo } from '../../app/repo';
describe(' >>> signIn', () => {
const action = {type: SIGN_IN, payload: {user: {uid:'DFDDGDG'}}};
const generator = signIn(action);
it('+++ must call AccountRepo.getAccount', () => {
//const generator = testFunction1("Gethyl")
const testValue = generator.next().value;
console.log(testValue);
expect(testValue).toEqual(call(AccountRepo.getAccount,action.payload.user))
});
} )
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP