Search code examples
testingbatman.js

Setup, runTests and teardown fails at Batman.TestCase


I am trying to get batman testing up and running. Qunit and tests runs fine, but when i use the example:

class SimpleTest extends Batman.TestCase
  @test 'A simple test', ->
    @assert true

test = new SimpleTest
test.runTests()

I get the following messages when i browse to localhost:3000/qunit:

  1. Setup failed on A simple test: undefined is not a function
  2. Died on test #2 at Test.Batman.TestCase.TestCase.Test.Test.run (localhost:3000/assets/extras/testing/test_case.js?body=1:20:22) at SimpleTest.Batman.TestCase.TestCase.runTests (localhost:3000/assets/extras/testing/test_case.js?body=1:51:28) at localhost:3000/assets/simple_test.js?body=1:24:8 at localhost:3000/assets/simple_test.js?body=1:26:4: undefined is not a function
  3. Teardown failed on A simple test: undefined is not a function

In the test_helper.coffee, I manually included the project, sinon and the four test case source files from the github source code found here, including test_case.coffee.

What am I doing wrong?


Solution

  • Depending on how those .coffee source files are loaded, it's possible that they don't have their dependencies loaded first.

    You could try this:

    • Download the 0.16 release from http://batmanjs.org/download.html
    • Use precompiled batman.testing.js from the release
    • Make sure QUnit loads batman.js first, then batman.testing.js. (Batman.Object must be defined before you load Batman.TestCase.)

    Does that help?