0
단위 테스트의 올바른 구문은 무엇입니까?자바 스크립트 단위 테스트 addEventListener 구문
다음은 브라우저에서 열 때 작동합니다. 의도는
var c5 = document.createElement('td');
var ib = document.createElement('input');
// For all browsers except IE before Version 9 -see http://help.dottoro.com/ljeuqqoq.php
if (ib.addEventListener)
{
ib.addEventListener('change', Action01InputBox (ib, c5), false);
}
// For IE before Version 9 -see http://help.dottoro.com/ljeuqqoq.php
else {
if (ib.attachEvent){
ib.addEventListener('change', Action01InputBox (ib, c5), false);
}
}
다음은 이벤트 리스너의 ...가 변경 될 때마다 입력 상자
ib
의 내용을 읽고, 및 테이블 셀
c5
로의 해석 값을 작성하는 것입니다. 물론 함수를 반환합니다.
NB EmptyNode(c5)
단순히 대상 노드의 내용을 모두 삭제하고 RealNumberFromInput (ib.value)
정규식 통해 입력 문자열에서 실수를 얻는 함수 ... 여기
function Action01InputBox (ib, c5)
{
return function()
{
EmptyNode(c5);
var r = RealNumberFromInput (ib.value);
c5.appendChild(document.createTextNode(r));
};
};
은 단위 테스트의 ...
Action01InputBoxTest = TestCase("Action01InputBoxTest");
Action01InputBoxTest.prototype.test01 = function()
{
// Text box
var r = 0.123;
var ib = document.createElement('input');
ib.setAttribute('value', document.createTextNode(r));
// Target cell
var c5 = document.createElement('td');
c5.appendChild(document.createTextNode("Bogus"));
// Do action
Action01InputBox(ib, c5);
assertEquals(c5.textContent, r);
};
은 "Bogus"에서 "0.123"으로 변경되어 테스트가 실패합니다.
제대로 이해한다면 문제는 테스트가 함수가 아니라 이벤트 수신기의 반환 값을 호출하지만 테스트에서 제대로 함수를 호출하는 방법을 찾지 못하는 것입니다.
미리 감사드립니다.