2

私は次のジャスミン仕様を持つ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を使用して、RailsAssetPipelineを使用して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

ありがとう!

4

1 に答える 1

6

describeブロック内に直接テストロジックを含めることはできません。すべてのテストロジックをitブロック内に配置する必要があります。

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

        expect($("tr.foo")).toBeHidden()
于 2012-06-25T15:20:17.503 に答える