Giter Site home page Giter Site logo

tad's Introduction

TAD - JavaScript test suite

Goal of this framework is to allow writing tests with minimal hassle. TAD will locate your test file, and provide tested module for your test functions.

Example console output:

$ npm install tad

Keep your tests in test folder. For each file in in main folder have corresponding test file in test folder.

Tests should be written as set of functions, it can be just one function:

module.exports = function (t, a, d) {
	// tests
};

or many thematically grouped functions:

exports["Test this"] = function (t, a, d) {
	// tests
};
exports["Test that"] = function (t, a, d) {
	// tests
};

Arguments passed to test functions are:

  • t - Tested module
  • a - Assert object
  • d - Done function, it's for tests that need to be run asynchronously. You may pass additional block of tests to this function and they'll be run right after. d argument makes no sense for synchrounous tests, declare such tests without it.

All arguments are optional, and by the way function is declared suite detect which arguments should be passed to test function. Examples:

  • Asynchronous test:
exports["Some tests"] = funtcion (t, a, d) {
		// tests
		setTimeout(function () {
		   // tests
		   d();
		}, 100);
};
  • Synchronous test:
exports["Some tests"] = function (t, a) {
	// tests
};

Tests can be nested, and declared various ways (synchronous/asynchronous)

module.exports["Test all"] = function (t, a) {
	// Preparation code

	// ... tests ...

	return {
		"Test this": function () {
			// We already have module and assert object
			// ... tests ...
		},
		"Test that async way": function (d) {
			// This one is asynchronous
			// ... tests ....

			seTimeout(function () {
				// ... tests ...
				d({
					"Some extra tests": function () {
							// ... tests ...
					}
				})
			}, 100);
		}
	};
};

TAD uses assert object from UncommonJS tests runner, It's API is nearly same as of assert that can be found in Node. Full spec is available at https://github.com/kriskowal/uncommonjs/blob/master/tests/specification.md .

TAD adds some extra sugar to UncommonJS Assert object:

  • a === a.strictEqual, so you can write your assertions as:
a(shouldBeTrue, true, "It's true");
// it has same effect as:
a.strictEqual(shouldBeTrue, true, "It's true");
  • a.not is an alias for a.notStrictEqual
  • a.deep is an alias for a.deepEqual
  • a.notDeep is an alias for a.notDeepEqual
  • assert.never with that you can check function paths that should never be called.

Test your file with provided binary:

$ bin/tad lib/test-file

or test all files in path:

$ bin/tad lib
  • Full custom context support
  • Code coverage
  • TAP support
  • jslint, jshint as side validation option
  • Port tests to browsers

tad's People

Contributors

medikoo avatar hosein2398 avatar

Watchers

James Cloos avatar  avatar

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.