Set up coffee script unit test in JsTestDriver

I am trying to implement a very simple unit test for CoffeeScript / JavaScript with JsTestDriver . I have 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 determines its path using the line: - lib/*.js However, when I run the test, I get: Total 0 tests (Passed 0; Fails: 0; Errors: 0)

I am sure that a test can be found because inserting an obvious program error leads to the detection of this error in a specific file. Also, inserting a warning call leads to the expected behavior: in the captured browser I see a warning message box

Am I missing something? How can you debug this?


Which works, but looks like this:

 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 are in the same folder, you can leave @

+4
source share
2 answers

See this question: ReferenceError: CoffeeScript + JsTestDriver + Qunit . You have the same problem because greet = defines a local variable that is not visible outside Greeter.coffee . Change it to window.greet = or @greet = .

However, this does not explain the Total 0 tests problem. I am not familiar with JsTestDriver, but on this page he suggested that test names should start with β€œtest” - maybe this capitalized name "Test 1" ignored? Try changing it to "test1" .

+3
source

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

+1
source

Source: https://habr.com/ru/post/1379835/


All Articles