2
votes

I'm writing a Rails app which has the following jasmine spec:

describe "buttons", ->

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

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

The spec failed with the error:

TypeError: Cannot call method 'expect' of null

So I put in the alerts. First we see ".hide-foo: 0", and then after I close that "beforeEach: 44" comes up. So clearly the error is because we're calling the expect before the fixture is loaded but...why the heck isn't beforeEach executed before each example?

I'm using jasminerice to use the Rails Asset Pipeline to compile my Coffeescript. Versions:

$ 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

Thanks!

1

1 Answers

6
votes

describe blocks should not have testing logic directly inside them. You should put all of your testing logic inside of an it block.

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

        expect($("tr.foo")).toBeHidden()