Unit.js is an open source unit testing framework for the
JavaScript programming language
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, often ...
,
running on
Node.js
Node.js is an open-source server environment. Node.js is cross-platform and runs on Windows, Linux, Unix, and macOS. Node.js is a back-end JavaScript runtime environment. Node.js runs on the V8 JavaScript Engine and executes JavaScript code ou ...
and the browser.
Usage
A simple
hello world
''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses
''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
test looks like the code below.
var example = 'Hello world!';
test.string(example)
.isEqualTo('Hello world!');
Support describe() and it(), describes a suite of tests and it() is an individual test specification. The name "it()" follows the idea of
behavior-driven development
In software engineering, behavior-driven development (BDD) is an agile software development process that encourages collaboration among developers, quality assurance experts, and customer representatives in a software project. It encourages teams ...
and serves as the first word in the test name, which should be a complete sentence.
describe('Hello world', function() );
Assertion styles
Unit.js has multiple interfaces that allow the developer to choose the most comfortable and productive style.
Unit.js :
test.string(str)
.number(num).is(42);
Assert :
test.assert(typeof str 'string');
test.assert(typeof num 'number');
test.assert.equal(num, 42);
Must.js :
test.must(str).be.a.string();
test.must(num).be.a.number();
test.must(num).equal(42);
Should.js :
test.should(str).be.a.String
test.should(num).be.Number
.and.equal(42);
See also
*
Unit testing
In computer programming, unit testing is a software testing method by which individual units of source codeāsets of one or more computer program modules together with associated control data, usage procedures, and operating procedures&m ...
*
List of unit testing frameworks
This article is a list of tables of code-driven unit testing frameworks for various programming languages. Some, but not all, of these are based on xUnit.
Columns (classification)
* Name: This column contains the name of the framework and wi ...
*
List of JavaScript libraries
This is a list of notable JavaScript libraries.
Constraint programming
* Cassowary (software)
* CHR.js
DOM (manipulation) oriented
* Google Polymer
* Dojo Toolkit
* jQuery
* midori
* MooTools
* Prototype JavaScript Framework
Graphical/v ...
*
JavaScript framework
A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build an ...
*
JavaScript library A JavaScript library is a library of pre-written JavaScript code that allows for easier development of JavaScript-based applications, especially for AJAX and other web-centric technologies.
Libraries
With the expanded demands for JavaScript, an e ...
References
{{reflist
External links
Unit.js websiteUnit.js on GitHub
JavaScript programming tools
Unit testing frameworks