2012-02-24 31 views
5

मैं एक साधारण जैस्मीन परीक्षण को लागू करने की कोशिश कर रहा हूं जिसमें कुछ कोड इनपुट बटन पर क्लिक होने पर जैस्मीन परीक्षण करेगा। लेकिन मुझे नहीं पता कि क्लिक क्यों ट्रिगर नहीं कर रहा है? मुझे एहसास है कि अगर मेरे पास पहले से .click() फ़ंक्शन है, लेकिन मुझे नहीं लगता कि यह काम करने का अनुमान है।जैस्मीन क्लिक ईवेंट ट्रिगर नहीं कर सकता

चश्मा

describe("export citations", function(){ 
    var btn 
    beforeEach(function(){    
    btn= $("input#myButton").eq(0); 
    }); 

    it("should call click function", function() { 
    btn.trigger("click"); 
    expect($("#content").length).toBeGreaterThan(0); 
    }); 
}); 

स्थिरता

$(function(){ 
    $("input#myButton").click(function(e){ 
    //Run a bunch of code here 
    } 
}); 

उत्तर

3

आप वास्तव में स्थिरता में डोम के लिए एक तत्व जोड़ दिया है? इसके अलावा आप एक गायब हैं); क्लिक कॉलबैक को बंद करने के लिए स्थिरता में।

यह मेरे लिए काम किया:

describe("export citations", function() { 
    var btn; 
    beforeEach(function() { 
    btn= $("input#myButton").eq(0); 
    }); 

    it("should call click function", function() { 
    btn.click(); 
    expect($("#content").length).toBeGreaterThan(0); 
    }); 
}); 

स्थिरता

(function() { 
    $("body").html("<input id='myButton' type='button'>"); 

    $("body").html("<div id='content'></div>"); 

    $("input#myButton").click(function() { 
    $("#content").html("<p>Hello</p>"); 
    }); 
})(); 
+0

कैसे/तुम कहाँ लोड कि इस तरह होना चाहिए अपने स्थिरता? –

+0

एक लंबे समय से मैंने इस पर काम किया है, लेकिन मुझे लगता है कि यह इसका वर्णन करता है: http://testdrivenwebsites.com/2010/07/29/html-fixtures-in-jasmine-using-jasmine-jquery/ – ebaxt

+0

धन्यवाद झुंड :) –

0

मुझे लगता है कि अपने दृढ़ अपने टेस्ट केस के अनुरूप करने के

(function() { 
     $("body").html("<input id='myButton' type='button'>"); 

     $("input#myButton").click(function() { 
      $("body").append("<div id='content'>") 
     }); 
    })(); 
संबंधित मुद्दे