You can use
assert.ok() for most verifications, but sometimes it can be difficult to determine the condition you are evaluating.
Read the example code below. Will this assertion throw an error?
const landAnimals = ['giraffe', 'squirrel']; const waterAnimals = ['shark', 'stingray']; landAnimals.push('frog'); waterAnimals.push('frog'); assert.ok(landAnimals == waterAnimals);
The above assertion is checking for equality. In order to understand this you must evaluate the entire expression within the parentheses of
You can instead use
assert.equal() which does the
== comparison for us.
In the example below, the two methods achieve the same outcome.
assert.ok(landAnimals == waterAnimals); assert.equal(landAnimals, waterAnimals);
The second line is more expressive: instead of parsing the entire statement, a reader only needs to read the first two words to know the test is verifying equality!
Replace the call to
assert.ok() with the equivalent call to
Though your test will work regardless of the order you pass the
expected results, it is common practice to pass
actual first and
Run the test suite.