reactjs - How to test assignment lines in saga function using jest -
i have function consists of saga effect calls want coverage full function out missing line of code how can test if condition here
export function* fetchfromsource() { const datatypename = mapdatatypes(datatype); iif (datatypename.length === 0) { return; } yield put(sourceactions.onrdsmsourceplantrequeststarted()); }
how test datatypename.length using jest this mapdatatypes unit test method
it('should return appropriate datatype when mapdatatypes triggered', () => { const expected = 'items'; const actiondatatype = action.payload.name; expect(expected).toequal(saga.mapdatatypes(actiondatatype)); });
this next put test method
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)); });
here test passing verify put call without entering if block. my question how verify if block
probably should change implementation of saga, , make mapdatatypes
call declarative: const datatypename = yield call(mapdatatypes, datatype)
. can test this:
it('should end saga when there 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)); });
Comments
Post a Comment