编写循环javascript函数的jasmine测试

时间:2014-05-29 09:38:46

标签: javascript unit-testing jasmine

该功能将是,

function checkCond(a, b){
    if(a===true){
        if(b===true){
            document.getElementById("theId").innerHtml = "success";
        }
        else if(b===false){
            document.getElementById("theId").innerHtml = "Fails";
        }
        else{
            document.getElementById("theId").innerHtml = "Required";
        }
    }
    else{
        if(b===true){
            document.getElementById("theId").innerHtml = "success";
        }
    }
}

我们如何为上述循环函数编写茉莉花测试?

1 个答案:

答案 0 :(得分:0)

我没有在这个函数中看到任何循环,但测试它应该足够简单。例如,

beforeEach(function() {
  // setup your dom element.  this depends on your environment and 
  // jasmine version.  see docs.  
});

it('should succeed when both conditions are true', function() {
   checkCond( true, true );
   expect(document.getElementById("theId").innerHtml).toBe "success"
});

等等。