Skip to content

contentjon/mocha-latte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mocha-latte

This library wraps the Mocha JavaScript testing framework, so it can be used with ClojureScript.

See the Mocha Documentation for a general introduction.

[mocha-latte "0.1.2"]

Since Mocha itself does not provide an assertion mechanism, you may want to use our ClojureScript wrapper for the Chai assertion library to write actual tests.

Installation

Before running tests, simply install mocha with npm.

npm install mocha -g

Running Tests

To run tests, compile your unit test code down to JavaScript. It is generally a good idea to let the closure compile do only simple optimizations. For an example setup see the project.clj in this repository.

When this is done, execute the test files by running mocha on them.

mocha <path to tests>

Example

(ns mylib.test.core
  (:require-macros [latte.core :refer (describe it)]))

(describe "Fruits"

  (describe "Apples"

    (it "is red" []
      ;; assertion code
      )))

Test Suite options

Mocha Test Suites and Test Cases support several options, which can be supplied as keyword arguments right before before the Suite or Test Case code.

(describe "Test Suites"

  (describe "with options"

    (it "get skipped" [] :skip true
      ;; assertion code
      )

    (it "runs only this test case" [] :only true
      ;; assertion code
      )))

Asynchronous Tests

Mocha supports asynchronous tests by supplying a done function to a test case. This is replicated in this library.

(describe "Asynchronous Test Suites"

  (it "runs asynchronously" [done]
    (js/setTimeout done 100))))

Additionally you may provide a timeout option to abort testing at the Suite or Test Case level.

(describe "Asynchronous Test Suites" :timeout 1000

  (it "times out after 500ms" [done] :timeout 500
    (js/setTimeout done 100))))

Test Fixtures

The regular Mocha before, each, beforeEach and afterEach Test Suite elements are supported, following the same syntax as the it macro. Test Fixture macros can be asynchronous via the done parameter. No options are implemented for these macros.

About

A ClojureScript wrapper for writing Mocha Test Suites

Resources

License

Stars

Watchers

Forks

Packages

No packages published