How to add custom success message in mocha tests?

by lindsey.homenick , in category: Javascript , a month ago

How to add custom success message in mocha tests?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , a month ago

@lindsey.homenick 

To add a custom success message in mocha tests, you can use the assert module that comes with Node.js. Here is an example of how you can add a custom success message:

1
2
3
4
5
6
7
8
9
const assert = require('assert');

describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.strictEqual([1, 2, 3].indexOf(4), -1, 'Value not found in the array');
    });
  });
});


In this example, the custom success message 'Value not found in the array' will be displayed if the test passes successfully. This can help provide more context and information about the test case.