Normally, a unit test will return true or false to determine if it passes or fails. If this is the case, you almost certainly want to use the T6.isTrue()
function. T6.isFalse()
can be used if a test needs to return false in order to pass. Here are a few simple examples of tests that will always pass using these functions.
Follow these steps to create a new project workspace and install the t6 dependency to run this example.
# Create and open project folder
mkdir Assert_Boolean_Values_demo
cd Assert_Boolean_Values_demo
# Initialize project and install dependencies
npm init -y
npm i t6@1.1.9
# Create and open source file
touch "Assert Boolean Values.mjs"
open "Assert Boolean Values.mjs"
Copy and paste this source code into Assert Boolean Values.mjs
.
import { T6 } from 't6';
// This function always returns true.
function alwaysReturnsTrue() {
return true;
}
// This test should pass
T6.isTrue(alwaysReturnsTrue());
// This function always returns false.
function alwaysReturnsFalse() {
return false;
}
// This test should pass
T6.isFalse(alwaysReturnsFalse());
// Show that all tests passed.
console.log('All tests passed!');
In Assert_Boolean_Values_demo/
, execute Assert Boolean Values.mjs
with NodeJS to generate an output.
node "Assert Boolean Values.mjs"
You should expect to see an output similar to the one below.
All tests passed!