首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jasmine,我尝试使用治具HTML,但是测试没有通过。

使用Jasmine,我尝试使用治具HTML,但是测试没有通过。
EN

Stack Overflow用户
提问于 2013-03-18 07:51:27
回答 2查看 1.9K关注 0票数 0

我是Jasmine-jQuery.的新手我试着使用工具HTML,但是测试没有通过。

fixture.html:

代码语言:javascript
复制
<html>
<body>
  <p id="0">
  </p>
</body>
</html>

fake_code_for_question_spec.coffee:

代码语言:javascript
复制
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:

代码语言:javascript
复制
root = exports ? this
class root.FakeCodeForQuestion
  addTextToParagraph0: ->
    $('p0').text "text"

茉莉花结果:

代码语言:javascript
复制
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)

谢谢你的好意。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-22 00:12:51

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2013-03-18 09:03:22

我认为您的文件夹结构不符合jasmine。loadFixtures()使用此目录路径spec/javascripts/fixtures。如果您进入jasmin代码库,查找fixturesPath,您将看到所有这些代码都使用spec/javascripts/fixtures。但是您可以通过使用jasmine.getFixtures().fixturesPath = "[your directory path here]";来覆盖这一点。

如果我能理解你的问题,我希望这会有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15471968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档