I have the following js file:
function createButtons(input) {
// implementation
}
function createMessage({buttonInput}) {
const message = {};
if(buttonInput) {
message.buttons = createButtons(buttonInput)
}
return message;
}
module.exports = {
createButtons,
createMessage
}
How can I create a mock of createButtons
to return a known value when I’m making a test for createMessage
?
I attempted create a mock by importing createButtons
and passing it to jest.spyOn
, but that doesn’t seem to work.
const spy = jest.spyOn(createButtons).mockImplementationOnce(() => true);
Is there a better way to write or test this?