我经常手动测试 JavaScript 函数的输出(通过简单地查看控制台中每个函数的输出),这通常很乏味。在 JavaScript 中,有没有办法自动测试一系列函数调用的输出,并返回所有没有产生预期结果的测试?
checkOutput([["add(1, 2)", 3], ["add(2, 2)", 4]]); //if the input does not match the output in one of these arrays, then return the function call(s) that didn't produce the correct output
function checkOutput(functionArray){
//this function is not yet implemented, and should return a list of function calls that did not produce correct output (if there are any).
}
function add(num1, num2){
return num1 + num2;
}