2013-03-22 41 views
0

我是新手Jasmine-jQuery。我試圖使用夾具HTML,但測試不通過。與Jasmine-jQuery我試圖改變夾具HTML,但它不起作用

fixture.html:

<html> 
<body> 
    <p id="0"> 
    </p> 
</body> 
</html> 

fake_code_for_question_spec.coffee:

describe "FakeCodeForQuestion", -> 
    describe "with HTML fixture", -> 
    beforeEach -> 
     loadFixtures "fixture.html" ### Load Fixture 
     @obj = new FakeCodeForQuestion 

    describe "#addText", -> 
     beforeEach -> 
     @obj.addTextToParagraph0() ### Change DOM 

     it "should add text", -> 
     expect($('p#0')).toHaveText "text" ### Get Changed DOM 

fake_code_for_question.coffee:

root = exports ? this 
class root.FakeCodeForQuestion 
    addTextToParagraph0: -> 
    $('p0').text "text" 

茉莉花結果:

Expected '<p id="0"> </p>' to have text 'text'. 

謝謝你的好意。

回答

1
root = exports ? this 
class root.FakeCodeForQuestion 
    addTextToParagraph0: -> 
    $('p0').text "text" 

嗨再次,這裏的問題是你的選擇犯規是指元件與P0的ID,而它指的是一個不存在的元素P0即類似於如何$(「身體」)選擇body元素。

你希望它是$('#p0'),而不是

+0

哦,非常感謝! – weed 2013-03-22 01:13:26

相關問題