【问题标题】:Writing jasmine test for looping javascript function为循环javascript函数编写茉莉花测试
【发布时间】:2014-05-29 09:38:46
【问题描述】:

函数是,

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

jasmine test 上面的循环函数怎么写?

【问题讨论】:

    标签: javascript unit-testing jasmine


    【解决方案1】:

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

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

    等等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2016-10-14
      • 2015-10-01
      • 1970-01-01
      相关资源
      最近更新 更多