I have two methods: second one is called by the first and I have to write test for the first one.
function func1(props, num) {
num.value +=1;
func2(props, num);
}
function func2(props, num) {
props.actions.getItDone().then((res) => {
num.value+=res.payload;
console.log(num);//i see 6 here but not in the test result.
});
}
Unit test file:
const props = {
actions: {
getItDone: () => {
return Promise.resolve({payload: 5 })
}
}
}
it('should verify something', () => {
const num = {value: 0};
func1(props, num);
expect(num.value).toBe(6); // it fails num.value coming here is 1.
});
it seems to me it's not waiting for the other method to complete. how can i make this return the correct value?