Skip to Content
Write Expressive Tests

Take a look at the code below. Will these assertions throw errors?

const a = 3; const b = '3'; assert.ok(a == b); assert.ok(a === b);
  • The first assertion will not throw an error because it uses loose (==) equality. It performs a type conversion when comparing two things.
  • The second will throw an error because it uses strict (===) equality. It returns false if the types differ.

If you need to be strict in evaluating equality, you can use assert.strictEqual().

  • assert.equal() performs a == comparison
  • assert.strictEqual() performs a === comparison

Compare the following code to the previous example. This code performs the same verifications, but it is more expressive. Without parsing any logic, a reader would know the intention of your tests by reading the method names.

const a = 3; const b = '3'; assert.equal(a, b); assert.strictEqual(a, b);



Set expected to the string '96' and run the test suite. The test still passes!


Replace assert.equal() with assert.strictEqual()


Run the test suite in the command line. The test fails!


Reset expected to 96 so that assert.strictEqual() does not return an error.


Run the test suite.

Folder Icon

Sign up to start coding

Already have an account?