I've got function provided by lib (project dependency from NPM). This function has a signature like
function dependency(
someParam: string,
callback: (data: string) => void
): void { ... }
This function has been called by my function (that I need to test) in the way like below:
async function tested(): Promise<string> {
return new Promise<string>((resolve): void => dependency('qwerty', resolve));
}
I need to test my tested
function with Jest but I'd like to test it in the unit-test style, so I need to mock the result from dependency
. This example is pretty simple, but in reality there are some additional logic that I need to give different data from dependency
.
Spying on this function informs me that it's being called, but I need to mock implementation and completely prevent executing of the lib's implementation.