2017-08-21 5 views
0

J'ai une fonction qui consiste d'appels à effet de saga que je veux une couverture la fonction complète avec des manquants toute ligne de code comment puis-je tester si la condition iciComment tester les lignes d'affectation en fonction de la saga en utilisant plaisanterie

export function* fetchFromSource() { 
const dataTypeName = mapDataTypes(dataType); 
     Iif (dataTypeName.length === 0) { 
     return; 
     } 
     yield put(sourceActions.onRdsmSourcePlantRequestStarted()); 
} 

comment je tester le dataTypeName.length en utilisant plaisanterie c'est ma mapDataTypes méthode de test unitaire

it('should return appropriate dataType when mapDataTypes triggered',() => { 
     const expected = 'Items'; 
     const actionDataType = action.payload.name; 
     expect(expected).toEqual(saga.mapDataTypes(actionDataType)); 
    }); 

ceci est ma méthode d'essai suivant mis

it('should return onRdsmSourcePlantRequestStarted action',() => { 
     const expectedAction = { 
     type: 'rdsm/sourceView/ON_RDSM_SOURCE_PLANT_REQUEST_STARTED', 
     }; 
     const dataTypeName = ''; 
     const genNext = generator.next(dataTypeName); 
     expect(genNext.value).toEqual(put(expectedAction)); 
    }); 

essai ici passe pour vérifier l'appel de vente sans entrer au bloc si. ma question est de savoir comment vérifier si le bloc

Répondre

0

vous devriez probablement changer la mise en œuvre de votre saga, et de faire appel mapDataTypes déclarative: const dataTypeName = yield call(mapDataTypes, dataType). Ensuite, vous pouvez le tester comme ceci:

it('should end saga when there is no dataTypeName',() => { 
    const dataTypeName = ''; 
    expect(generator.next().value).toEqual(call(mapDataTypes, dataType)); 
    expect(generator.next(dataTypeName).done).toBeTruthy(); 
}); 

it('should return onRdsmSourcePlantRequestStarted action',() => { 
    const expectedAction = { 
    type: 'rdsm/sourceView/ON_RDSM_SOURCE_PLANT_REQUEST_STARTED', 
    }; 
    const dataTypeName = 'something'; 
    expect(generator.next().value).toEqual(call(mapDataTypes, dataType)); 
    expect(generator.next(dataTypeName).value).toEqual(put(expectedAction)); 
}); 
0

pour tester bloc autre

it('should return onRdsmSourcePlantRequestStarted action',() => { 
     const expectedAction = { 
     type: 'rdsm/sourceView/ON_RDSM_SOURCE_PLANT_REQUEST_STARTED', 
     }; 
     const dataTypeName = 'test'; 
     expect(generator.next(dataTypeName).value).toEqual(put(expectedAction)); 
    }); 

test si le bloc

it('should return undefined ',() => { 
      const dataTypeName = ''; 
     expect(generator.next(dataTypeName).value).toBe(undefined)); 
     });