I have a function that prints a string
I want to test that function actually prints the string provided
The way I understand this should work is: 1. store the log in a var 2. assert content stored in the var is toBe what I expect
const log = 'hello2';
let myFunction = (log) => {
console.log(log);
};
myFunction(log);
const {myFunction} = require('../function-conversion');
test('Function prints message: "hello"', () => {
expect(myFunction(log).toBe(console.log("hello")))
});
Function prints message: "hello" (1ms)
Function prints message: "hello"
ReferenceError: log is not defined
at Object.log (tests/function-conversion.test.js:4:20)
console.log ../function-conversion.js:11 hello2
console.logdoes not return a value. If you want to test that a function actually prints out something, you have to redirect the standard output stream to a file and check its contents after writing.