Open yeppin opened 3 years ago
I am not sure I got your point correctly, but although the functions become fake(mock) with spyOn, you could cover up the actual codes by modifying its return value.
like,
with jest.spyOn(window, 'confirm').mockImplementation(() => true);
you can test execution inside of the function for
if (window.confirm('confirm description.')){
// function execution
};
Same for window.prompt as well. Please let us know if we misunderstood your point
Thanks to the reply, I think I found the answer. Thank you!
I have a question regarding simulating user's action in window.confirm and window.prompt function. So far I wrote tests which check whether those functions have been called or not. However I would like to handle further testing with the returned value from window.confirm / window.prompt.
These are the examples of codes that need to be tested,
I have been trying by using spyOn operation to window functions with .mockImplementation and .mockReturnedValue. However as the functions become fake, its value could not cover up the actual codes that execute with actual return value. is there a way to simulate window functions and test with its returned value?
Thank you