Javascript Test - Assertion library


assertion in Javascript


They just throws an Error when the assertion is not satisfied.

Devtool Console

Chrome console

function greaterThan(a,b) {
  console.assert(a > b, {"message":"a is not greater than b","a":a,"b":b});

Implementation Example

  • The function to test named plus1
function plus1(a){
    return a + 1;
  • The test function of the plus1 function
function assertEqual(then, expected) {
    if (result == expected) {
        console.log("The assertion was successful")
    } else {
        console.log("The assertion was not successful. then="+then+", expected="+expected)
  • The test
var result = plus1(1);
var expectation = 2;
assertEqual(result, expectation);
  • The result

Discover More
Javascript - Karma (Test runner)

Karma is a javascript test runner that permit to execute test code in multiple real browsers via phantomJs. Karma is not a testing framework, nor an assertion library. Karma just launches an HTTP server,...
Javascript - Test Framework

in Javascript A test framework is composed of two part that you can use separately: a an assertion library The function to test named plus1 The test function of the plus1 function The...

Share this page:
Follow us:
Task Runner