Get started with should.js CDN
MIT licensed
Should.js: Popular Node.js assertion library. Simple, expressive unit testing with chaining.
Tags:- test
- bdd
- assert
- should
Stable version
Copied!
How to start using should.js CDN
// Include Should.js library
const should = require('should');
// Set up some data for testing
const expectedNumber = 42;
const actualNumber = 42;
const expectedString = 'hello world';
const actualString = 'hello world';
// Test number equality
should(actualNumber).be.exactly(expectedNumber).and.not.be.null();
// Test string equality
should(actualString).be.exactly(expectedString).and.not.be.null();
// Test array equality
const expectedArray = [1, 2, 3];
const actualArray = [1, 2, 3];
should(actualArray).deepEqual(expectedArray).and.not.be.null();
// Test object equality
const expectedObject = { name: 'John Doe', age: 30 };
const actualObject = { name: 'John Doe', age: 30 };
should(actualObject).deepEqual(expectedObject).and.not.be.null();
// Test if a value is truthy or falsy
const truthyValue = 10;
const falsyValue = 0;
should(truthyValue).be.truthy();
should(falsyValue).be.falsy();
// Test if a value is an instance of a constructor
const expectedInstance = new Date();
const actualInstance = new Date();
should(actualInstance).instanceOf(Date).and.not.be.null();
// Test if a value is a type (number, string, boolean, etc.)
should(expectedNumber).be.a.Number();
should(expectedString).be.a.String();
should(expectedString).be.a.String().that.is.a.palindrome(); // Custom assertion
// Test if an error is thrown
function divideByZero(num) {
return num / 0;
}
should(divideByZero).throw(Error, 'Division by zero');
Copied!
Copied!
Copied!
All versions
10.0.0
11.0.0
11.1.0
11.1.1
11.1.2
11.2.0
11.2.1
12.0.0
13.0.1
13.1.0
13.1.1
13.1.2
13.1.3
13.2.0
13.2.1
13.2.2
*** 13.2.3
2.0.0
2.0.1
2.0.2
2.1.0
2.1.1
3.0.0
3.0.1
3.1.0
3.1.1
3.1.2
3.1.3
3.1.4
3.2.0
3.2.0-beta1
3.3.0
3.3.1
3.3.2
4.0.0
4.0.1
4.0.2
4.0.3
4.0.4
4.1.0
4.2.0
4.2.1
4.3.0
4.3.1
4.4.0
4.4.1
4.4.2
4.4.3
4.4.4
4.5.0
4.5.1
4.5.2
4.6.0
4.6.1
4.6.2
4.6.3
4.6.4
4.6.5
5.0.0
5.0.1
5.1.0
5.2.0
6.0.0
6.0.1
6.0.2
6.0.3
7.0.0
7.0.1
7.0.2
7.0.3
7.0.4
7.1.0
7.1.1
8.0.0
8.0.1
8.0.2
8.1.0
8.1.1
8.2.0
8.2.1
8.2.2
8.3.0
8.3.1
8.3.2
8.4.0
9.0.0
9.0.1
9.0.2