How to use 'console.assert' for assertion in JavaScript

console.assert prints text passed as second argument if the first argument returns false;
for example,


const notTrue = false;

console. assert(notTrue, 'I\'ts false')

// return "it's false"

You can use console.assert to perform simple unit tests of your JavaScript application.


const application = function(params){
    if(params.num < 10)
    return false
    else return true
}

const instance = new application({
    num: 5
})

console.assert(instance, 'number less than ten')

// return "number less than ten"

Comments

Popular posts from this blog

FlappingBird Postmortem (JS13K)

JavaScript introduction to variables

FlappingBird JS13K Games

How to target all elements of a given class name in JavaScript

Zedplug will be decommissioned on November 30th