0

私はJasmine-jQueryの初心者です。フィクスチャ HTML を使用しようとしましたが、テストに合格しません。

フィクスチャ.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)

ご親切にありがとうございました。

4

2 に答える 2

2

あなたのフォルダー構造はjasmine-jqueryに従っていないと思います。はこのloadFixtures()ディレクトリ パスを使用しますspec/javascripts/fixtures。jasmin-jquery のコード ベースにアクセスして を探すとfixturesPath、それらすべてで が使用されていることがわかりますspec/javascripts/fixtures。ただし、を使用してこれをオーバーライドできますjasmine.getFixtures().fixturesPath = "[your directory path here]";

あなたの質問を理解できれば、これが役立つことを願っています。

于 2013-03-18T09:03:22.220 に答える
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 が必要です

于 2013-03-22T00:12:51.457 に答える