0.2.0 • Published 12 years ago

janitor v0.2.0

Weekly downloads
29
License
-
Repository
-
Last release
12 years ago

Janitor

Janitor lets you write unit tests in Coffeescript that resemble tests written with Ruby's Test::Unit. You can use it with node or in the browser.

Why use janitor?

  • Because you, like me, like the simplicity of Ruby's Test::Unit and want to work the same way in Coffeescript.
  • Because you like having the ability to test asynchronous code without being required to call @complete() in each of your synchronous tests.

In the browser

Get the most recent dist file and include it on your test page. Define your tests like so:

class window.UserTest extends Janitor.TestCase
  'test mood': ->
    user = new User mood: 'happy'
    @assert user.isHappy()

Then, run your tests like this:

runner = new Janitor.BrowserRunner el: document.getElementById('js_test_results')
runner.run()

Test results will now be outputted to the #js_test_results element.

In node

Add the following to your Cakefile (read more about Cakefiles).

task 'test', 'Run test suite', ->
  Janitor = require 'janitor'
  runner = new Janitor.NodeRunner { dir: __dirname + '/test' }
  runner.run()

Run cake test to see test results in the terminal.

Extras

Janitor supports setup (and teardown):

MyLib = require '../.'

module.exports = class extends Janitor.TestCase
  setup: ->
    @obj = new MyLib
    
  'test something': ->
    @assert @obj.allIsWell()
    
  'test something': ->
    @assert @obj.everythingOk()

You can also test asynchronously by using async test prefix instead of test:

module.exports = class extends Janitor.TestCase
  'async test something': ->
    obj = new MyLib
    obj.doSomething =>
      @assert obj.allIsWell()
      @complete()
0.2.0

12 years ago

0.1.8

12 years ago

0.1.7

12 years ago

0.1.6

12 years ago

0.1.5

12 years ago

0.1.4

12 years ago

0.1.3

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago