testla

An opinionated and lightweight testing framework

testla

an opinionated and lightweight testing framework for the browser and node.js

npm install -g testla
testla [FILE, ...]

Running individual tests

testla file1-test.js file2-test.js

Running all tests in folder

testla tests/
  • Modules
  • Dependency Injection
  • Browser, framework, and platform independent
  • Intuitive and lightweight syntax

Similar to node.js assert

fail
ok
equal
notEqual
strictEqual
notStrictEqual
deepEqual
notDeepEqual
throws
doesNotThrow

Other included matchers

isFunction
isNumber
isString
isBoolean
isArray
isObject
isArguments
isDate
isRegExp
isUndefined
isNull
isNaN
isTrue
isFalse
isEmpty

In your dependencies.js file export a function which returns an object literal of dependencies. Here you can use assert.extend() to create your own custom matchers.

module.exports = function (assert) {
  assert.extend({
    myCustomMatcherfunction (abmessage) {
      assert.equal(a, b, message)
    }
  })
 
  return {
    myDep: 1,
    otherDependency: 'hello'
  }
}

Spies are useful for hooking into functions and asserting that they have been called and with the correct parameters.

To work with spies just include spy in your test function's parameters.

var obj = { foofunction () { } }
 
'a spy test'function (spy) {
  var mySpy = spy.on(obj, 'foo')
  obj.foo('bar')
  mySpy.assert('bar')
}

Relies on promises to provide asynchronous tests. One can reject or fail the test or resolve/complete the test. Returning the promise is essential to mark the test as asynchronous and inform testla to wait for the test to finish.

'an async test'function (promise) {
  setTimeout(function () {
    promise.resolve(4)
  }, 500)
 
  return promise
}

License

MIT LICENSE