In Chai.js, assert.isNull()
is used to check if a value is null
or not.
It returns an error if the value passed is not null
, and it returns nothing if the value passed is null
.
assert.isNull(val)
val
: This is the value we want to check.
If the test succeeds, it returns. If the test fails, it returns an error.
// import the chai module and assert interfaceconst {assert} = require('chai')// function to check if values are nullconst checkIfNull= (val1, val2) =>{try{// use the isNull() methodassert.isNull(val1)}catch(error){console.log(error.message)}}checkIfNull(true)checkIfNull(false)checkIfNull(null) // test succeededcheckIfNull(undefined)checkIfNull(0)
chai
module as well as the assert.isNull()
method.assert.isNull()
method. It takes the value we want to check if they are null
. We use the try/catch
block to catch any errors if the test fails.null
.