\href{https://travis-ci.org/browserify/commonjs-assert}{\texttt{ }}

This module is used for writing unit tests for your applications, you can access it with `require(\textquotesingle{}assert')\`{}.

It aims to be fully compatibe with the \href{http://nodejs.org/api/assert.html}{\texttt{ node.\+js assert module}}, same API and same behavior, just adding support for web browsers. The API and code may contain traces of the \href{http://wiki.commonjs.org/wiki/Unit_Testing/1.0}{\texttt{ Common\+JS Unit Testing 1.\+0 spec}} which they were based on, but both have evolved significantly since then.

A {\ttfamily strict} and a {\ttfamily legacy} mode exist, while it is recommended to only use {\ttfamily strict mode}.\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3262}{}\doxysection{Strict mode}\label{md_sfcode_node_modules_assert_README_autotoc_md3262}
When using the {\ttfamily strict mode}, any {\ttfamily assert} function will use the equality used in the strict function mode. So {\ttfamily assert.\+deep\+Equal()} will, for example, work the same as {\ttfamily assert.\+deep\+Strict\+Equal()}.

It can be accessed using\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const assert = require('assert').strict; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3263}{}\doxysection{Legacy mode}\label{md_sfcode_node_modules_assert_README_autotoc_md3263}
\begin{quote}
Deprecated\+: Use strict mode instead. \end{quote}
When accessing {\ttfamily assert} directly instead of using the {\ttfamily strict} property, the \href{https://tc39.github.io/ecma262/\#sec-abstract-equality-comparison}{\texttt{ Abstract Equality Comparison}} will be used for any function without a \char`\"{}strict\char`\"{} in its name (e.\+g. {\ttfamily assert.\+deep\+Equal()}).

It can be accessed using\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const assert = require('assert'); }

\end{DoxyCode}


It is recommended to use the {\ttfamily strict mode} instead as the Abstract Equality Comparison can often have surprising results. Especially in case of {\ttfamily assert.\+deep\+Equal()} as the used comparison rules there are very lax.

E.\+g.


\begin{DoxyCode}{0}
\DoxyCodeLine{// WARNING: This does not throw an AssertionError!}
\DoxyCodeLine{assert.deepEqual(/a/gi, new Date()); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3264}{}\doxysection{assert.\+fail(actual, expected, message, operator)}\label{md_sfcode_node_modules_assert_README_autotoc_md3264}
Throws an exception that displays the values for actual and expected separated by the provided operator.\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3265}{}\doxysection{assert(value, message), assert.\+ok(value, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3265}
Tests if value is truthy, it is equivalent to assert.\+equal(true, !!value, message);\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3266}{}\doxysection{assert.\+equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3266}
Tests shallow, coercive equality with the equal comparison operator ( == ).\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3267}{}\doxysection{assert.\+not\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3267}
Tests shallow, coercive non-\/equality with the not equal comparison operator ( != ).\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3268}{}\doxysection{assert.\+deep\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3268}
Tests for deep equality.\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3269}{}\doxysection{assert.\+deep\+Strict\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3269}
Tests for deep equality, as determined by the strict equality operator ( === )\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3270}{}\doxysection{assert.\+not\+Deep\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3270}
Tests for any deep inequality.\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3271}{}\doxysection{assert.\+strict\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3271}
Tests strict equality, as determined by the strict equality operator ( === )\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3272}{}\doxysection{assert.\+not\+Strict\+Equal(actual, expected, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3272}
Tests strict non-\/equality, as determined by the strict not equal operator ( !== )\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3273}{}\doxysection{assert.\+throws(block, \mbox{[}error\mbox{]}, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3273}
Expects block to throw an error. error can be constructor, regexp or validation function.

Validate instanceof using constructor\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.throws(function() \{ throw new Error("{}Wrong value"{}); \}, Error); }

\end{DoxyCode}


Validate error message using Reg\+Exp\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.throws(function() \{ throw new Error("{}Wrong value"{}); \}, /value/); }

\end{DoxyCode}


Custom error validation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.throws(function() \{}
\DoxyCodeLine{    throw new Error("{}Wrong value"{});}
\DoxyCodeLine{\}, function(err) \{}
\DoxyCodeLine{    if ( (err instanceof Error) \&\& /value/.test(err) ) \{}
\DoxyCodeLine{        return true;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}, "{}unexpected error"{}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3274}{}\doxysection{assert.\+does\+Not\+Throw(block, \mbox{[}message\mbox{]})}\label{md_sfcode_node_modules_assert_README_autotoc_md3274}
Expects block not to throw an error, see assert.\+throws for details.\hypertarget{md_sfcode_node_modules_assert_README_autotoc_md3275}{}\doxysection{assert.\+if\+Error(value)}\label{md_sfcode_node_modules_assert_README_autotoc_md3275}
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks. 