2013-03-18 30 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')).toHavaText "text" ### Get Changed DOM 

fake_code_for_question.coffee:

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

茉莉花結果:

FakeCodeForQuestion with HTML fixture #addText should add text. 
TypeError: Object [object Object] has no method 'toHavaText' 
TypeError: Object [object Object] has no method 'toHavaText' 
    at null.<anonymous> (http://localhost:8888/__spec__/p130318_fake_code_for_question_spec.js:14:35) 
    at jasmine.Block.execute (http://localhost:8888/__jasmine__/jasmine.js:1064:17) 
    at jasmine.Queue.next_ (http://localhost:8888/__jasmine__/jasmine.js:2096:31) 
    at goAgain (http://localhost:8888/__jasmine__/jasmine.js:2086:18) 

謝謝你的好意。

回答

2
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')).toHavaText "text" ### Get Changed DOM 

你得到的結果是,沒有方法「toHavaText」給你的指示,你想toHaveText代替

2

我認爲你的文件夾結構不符合jasmine-jquery。 loadFixtures()使用此目錄路徑spec/javascripts/fixtures。如果您進入jasmin-jquery代碼庫,請查找fixturesPath,您會發現它們全部使用spec/javascripts/fixtures。但是您可以使用jasmine.getFixtures().fixturesPath = "[your directory path here]";覆蓋此值。

我希望這個幫助,如果我明白你的問題。