AssertJS
Javascript, battle tested, simple assertion library with no dependencies.
Example:
/** * @param */{ Assert; // do your job}
Now you are covered by the Assertion, and you don't need to be worried that someone might pass empty object {} to doSomethingWithHtmlElement.
doSomethingWithHtmlElement
function was designed to accept only HTMLElement, nothing more!
Usage
npm install assert-js --save
let Assert = Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assertobjectid: 1;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;Assert;
Assert;
Asserts that expression or value is equal to true.
Example:
Assert; // this will throw an Error.let falseValue = false;Assert; // this will throw an Error.
Assert;
Asserts that expression or value is equal to false.
Example:
Assert; // this will throw an Error.let falseValue = true;Assert; // this will throw an Error.
Assert;
Asserts that value is an instance of specific class.
Example:
let div = windowdocument;Assert;
Assert;
Asserts that value is an instance of at least one specific class.
Example:
let div = windowdocument;Assert;
Assert;
Asserts that array contains only instances of specific class.
Assert;
Asserts that array contains only strings.
Assert;
Asserts that array contains only integers.
Assert;
Asserts that array contains only numbers.
Assert;
Asserts that value is valid integer.
Assert;
Asserts that value is valid number (integer, float).
Assert;
Asserts that value is odd number.
Assert;
Asserts that value is event number.
Assert
Asserts that number is greater than.
Assert
Asserts that number is greater than or equal.
Assert
Asserts that number is less than.
Assert
Asserts that number is less than or equal.
Assert;
Assert that value is valid string.
Assert;
Asserts that value is valid boolean.
Assertobject1 1;
Asserts that value is equal to expected value.
Assert;
Asserts that object is equal to expected object.
Assertobjectid: 1;
Asserts that value is valid object.
Assert;
Asserts that object has function.
Assert;
Asserts that object has property (it can also be a function).
Assert;
Asserts that value is valid function.
Assert;
Asserts that value is valid array.
Assert;
Asserts that value is one of expected values.
Assert;
Asserts that array have specific number of elements.
Assert;
Asserts that array is not empty.
Assert;
Asserts that value is valid json string.
Assert;
Asserts that string is valid email address.
Assert;
Asserts that string is valid url.
Assert;
Asserts that string is valid UUID.
Assert;
Asserts that element has other element under selector.
Example:
let dom = `<body><div id="div"></div></body>`; Assert;
Assert;
Asserts that element has expected attribute (it might be empty).
Example:
let dom = `<body><div id="div" data-test></div></body>`; Assert;
Assert;
Asserts that element has expected attributes (it might be empty).
Example:
let dom = `<body><div id="div" data-test></div></body>`; Assert;
Assert;
Asserts that function throws expected exception.
Example:
Assert;Assert;Assert;Assert;Assert;
Custom exception message
In order to customize error messages (for easier debugging) you can pass error message as a last parameter into all assertions.
Examples:
Assert;
you can also use variables expected
and received
in your messages.
Assert; // it throws Error("Expected string but got int[1234]")