我是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 DOMfake_code_for_question.coffee:
root = exports ? this
class root.FakeCodeForQuestion
addTextToParagraph0: ->
$('p0').text "text"茉莉花结果:
Expected '<p id="0"> </p>' to have text 'text'.谢谢你的好意。
发布于 2013-03-22 01:03:03
root = exports ? this
class root.FakeCodeForQuestion
addTextToParagraph0: ->
$('p0').text "text"嗨,这里的问题是您的选择器没有引用id为p0的元素,而是引用了一个不存在的元素p0,即类似于$(' body ')如何选择body元素。
您希望它是$('#p0')而不是
https://stackoverflow.com/questions/15560764
复制相似问题