编写茉莉测试循环javascript函数

Writing jasmine test for looping javascript function

本文关键字:循环 javascript 函数 测试      更新时间:2023-09-26

函数是,

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";
        }
    }
}

我们如何为上面的循环函数编写for jasmine test ?

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

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"
});

等等。