4

I am trying to implement a very basic unit test for CoffeeScript/JavaScript with JsTestDriver. I've got two files:

1.) lib/Greeter.coffee

greet = (name) ->
    "Hello #{name}"

2.) lib/GreeterTest.coffee

tests = {
    "Test 1": -> assertEquals("Hello World!", greet "World")
}

TestCase("Test for introducing the test framework", tests)

My jsTestDriver.conf defines their path with the line: - lib/*.js When executing the test, however, I get: Total 0 tests (Passed 0; Fails: 0; Errors: 0)

I am sure, that the test can be located, because inserting an obvious program error leads to the detection that error in the concrete file. Also inserting an alert invocation leads to the expected behavior: In the browser being captured I see the alert-Message Box

Am I missing something? How could something like this be debugged?


What does work though is the following:

TestCase("Test case 1", {

    testGreet: ->
        greeter = new Greeter
        assertEquals("Hello World!", greeter.greet "World")
})

and

class @Greeter

   constructor: ->

   greet: (name) ->
        return "Hello #{name}!"

If both files reside in the same folder, you can drop the @

Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143

2 Answers2

3

See this question: ReferenceError: CoffeeScript + JsTestDriver + Qunit. You've got the same issue, in that greet = defines a local variable that isn't visible outside of Greeter.coffee. Change it to window.greet = or @greet =.

However, that doesn't explain the Total 0 tests issue. I'm not intimately familiar with JsTestDriver, but on this page it's suggested that test names have to start with "test"—could it be that the capitalized name "Test 1" is ignored? Try changing it to "test1".

Community
  • 1
  • 1
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
1

Make sure that when you run java -jar $JSTESTDRIVER -tests all you are in the some directory as your test, this should take care of the "total 0 test" issue. I had the same problem.

juan
  • 21
  • 1
  • No, it was actually caused that I didn't named the test functions with prefix "test..", but +1 for telling another possible reason! – Konrad Reiche Dec 16 '11 at 20:18