(이것은 확실히 솔루션의 일부이지만) 내가 조금 더 Gepser의 솔루션 @ 걸릴 것
. 이름으로 폼을 잡고 싶다면 각 테스트 전에 HTML을 재설정하기 위해 QUnit의 fixture를 사용하고 싶을 것입니다. 그런 다음 alert
메소드를 조롱하여 테스트하는 동안 그 중 많은 것을 얻지 못하게 할 수 있습니다. 당신의 QUnit 테스트에서 다음
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<!-- Anything in here gets reset before each test -->
<form name="formSecond">
<input type="text" name="nameFull">
</form>
</div>
...
</body>
(그 중 하나 HTML에 자신의 JS 파일에 우리의 파일) : 다음 QUnit의 HTML 파일에서
는
QUnit.begin(function() {
// mock out the alert method to test that it was called without actually getting an alert
window.alert = function() {
window.alert.called++;
};
window.alert.called = 0;
});
QUnit.testDone(function() {
// reset the alert called count after each test
window.alert.called = 0;
});
...
// From @Gepser's answer...
QUnit.test("CheckingName", function(assert) {
var value = false;
assert.equal(value, validNameCheck(), "We expect the return to be false");
// add an assertion to make sure alert was called
assert.equal(1, window.alert.called, "alert was called only once");
});
인수'form'는 것으로 보인다 미사용의 –