Feel Physics
Feel Physics

Reputation: 2783

With Jasmine-jQuery I tried to use fixture HTML but test doesn't pass

I am newbie of Jasmine-jQuery. I tried to use fixture HTML but test doesn't pass.

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"

Jasmine Result:

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)

Thank you for your kindness.

Upvotes: 0

Views: 1902

Answers (2)

ridget
ridget

Reputation: 202

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

The result you got, no method 'toHavaText' gives you the indication, you want toHaveText instead

Upvotes: 2

Shaoz
Shaoz

Reputation: 10653

I think your folder structure is not in accordance with jasmine-jquery. The loadFixtures() uses this directory path spec/javascripts/fixtures. If you go into jasmin-jquery code base, look for fixturesPath, you'll see that all of them use spec/javascripts/fixtures. But you can override this by using jasmine.getFixtures().fixturesPath = "[your directory path here]";.

I hope this help, if I understand your question.

Upvotes: 2

Related Questions