【问题标题】:Jasmine calling beforeEach after testsJasmine 在测试后调用 beforeEach
【发布时间】:2012-06-26 20:28:57
【问题描述】:

我正在编写一个具有以下茉莉花规格的 Rails 应用程序:

describe "buttons", ->

  beforeEach ->
    loadFixtures("foo.html")
    alert("beforeEach: " + $("tr.foo").length)

  describe ".hide_foo", ->
    alert(".hide-foo: " + $("tr.foo").length)
    ...
    expect($("tr.foo")).toBeHidden()

规范因错误而失败:

TypeError: Cannot call method 'expect' of null

所以我设置了警报。首先我们看到“.hide-foo: 0”,然后在我关闭之后出现“beforeEach: 44”。很明显,错误是因为我们在加载夹具之前调用了expect,但是......为什么beforeEach 不是在每个示例之前执行

我正在使用 jasminerice 来使用 Rails 资产管道来编译我的 Coffeescript。版本:

$ bundle show jasmine && bundle show jasminerice
/home/tmacdonald/.rvm/gems/ruby-1.9.2-p320/gems/jasmine-1.2.0
/home/tmacdonald/.rvm/gems/ruby-1.9.2-p320/gems/jasminerice-0.0.9

谢谢!

【问题讨论】:

    标签: javascript unit-testing coffeescript jasmine


    【解决方案1】:

    describe 块不应直接在其中包含测试逻辑。您应该将所有测试逻辑放在 it 块中。

    describe ".hide_foo", ->
        it 'should hide the row', ->
            alert(".hide-foo: " + $("tr.foo").length)
    
            expect($("tr.foo")).toBeHidden()
    

    【讨论】:

    • 天哪,我需要更多的睡眠。谢谢你。我现在就出去看看。
    猜你喜欢
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多