tad

2019-01-12 admin

tad是什么

什么是tad,JavaScript test suite

tad使用教程帮助文档

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:

  • Installation
  • Usage
    • File managment
    • Test files
    • Test functions
    • Assertions
    • Running tests
  • TODO

<a name=“user-content-installation”></a>

<a name=“user-content-installation”></a>Installation

$ npm install tad

<a name=“user-content-usage”></a>

<a name=“user-content-usage”></a>Usage

<a name=“user-content-usage-file-management”></a>

<a name=“user-content-usage-file-management”></a>File management

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

<a name=“user-content-usage-test-files”></a>

<a name=“user-content-usage-test-files”></a>Test files

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
};

<a name=“user-content-usage-test-functions”></a>

<a name=“user-content-usage-test-functions”></a>Test functions

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);
		}
	};
};

<a name=“user-content-usage-assertions”></a>

<a name=“user-content-usage-assertions”></a>Assertions

<a name=“user-content-usage-assertions”>TAD uses assert object from</a> 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.

<a name=“user-content-usage-running-tests”></a>

<a name=“user-content-usage-running-tests”></a>Running tests

Test your file with provided binary:

$ bin/tad lib/test-file

or test all files in path:

$ bin/tad lib

<a name=“user-content-todo”></a>

<a name=“user-content-todo”></a>TODO

  • Full custom context support
  • Code coverage
  • TAP support
  • jslint, jshint as side validation option
  • Port tests to browsers

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-50790.html

文章标题:tad

相关文章
metadataify
metadataify是什么 什么是metadataify,Stream meta tags into html metadataify官网:官网 metadataify源码仓库:源码仓库 metadataify下载地址:点此下载 点此下...
2019-04-13
HTML 音频/视频 DOM loadedmetadata 事件
&lt;p&gt;&lt;a href=“ref-av-dom.html”&gt;&lt;img class=“navup” src=&quot;/public/upload/imgs/up.gif&quot; alt=“HTML audi...
2019-04-01
回到顶部