JavaScript 함수의 출력을 수동으로 (콘솔의 각 함수의 출력을 보는 것만으로) 테스트하는 경우가 종종 있습니다. 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;
}
이 줄에는 괄호가 없습니다 :'return eval (e [0])! == e [1]); ' –
그 점을 지적 해 주셔서 감사합니다. 원래'if'로 작성 했었습니다. –
다음은 JSFiddle에서이 함수를 테스트 한 것입니다. http://jsfiddle.net/jarble/xZ5uy/ –