I need to write a test for a function in jest. I have function like following:
async function fun(conn, input){
const connection = conn.getConnection();
....
// some output gets generated from input
// const processed_input = input???;
....
const x = util.promisify(connection.query).bind(connection);
return /* await */ x(processed_input);
}
I want to expect the value of processed_input
that is passed to function x
.
I thought that something like .toHaveBeenCalledWith
should work I am not sure how it works for promisified binded functions.
I also tried to mock query doing something like conn.getConnection = { query: jest.fn() }
before the fun
call but I'm not sure how to move forward to expect
it.
Update:
So far my current solution is to have jest expect
statements inside query function.
conn.getConnection = {
query: function(processed_input){ //expect processed_input to be; }
}`
Hoping for a better way.