Giter Club home page Giter Club logo

testla's Introduction

NPM version Dependency Status

testla

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

install

npm install -g testla

reference

testla [FILE, ...]

Running individual tests

testla file1-test.js file2-test.js

Running all tests in folder

testla tests/

ideas

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

matchers

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

custom matchers

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({
    myCustomMatcher: function (a, b, message) {
      assert.equal(a, b, message)
    }
  })

  return {
    myDep: 1,
    otherDependency: 'hello'
  }
}

spies

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 = { foo: function () { } }

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

asynchronous

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.