Can anyone teach me how to use mocha for unit testing?

  node.js, question

I am a PHP programmer. The leader asked me to study this and told him how to use it. After reading a lot of tutorials online, I don’t know what BDD is, TDD, how to test, what is the process, how to use mocha. Can the great god elaborate?

Configure test environment

  1. Configure gulpfile, never gulp gulpfile? Please moveGulp.com

  2. Install test tool mochanpm install gulp-mocha --save-dev

  3. Writing a test task

    gulp.task('test-api', function () {
     return gulp.src('test.js')
     .pipe(mocha())
     .once('error', function () {
     process.exit(1);
     })
     .once('end', function () {
     process.exit();
     });
     });
  4. Writing test cases in test.js

    var assert = require("assert");
     var rest = require("restler");  //Middleware to Request API Interface
     var apiCtrl = require('../controllers/api');  //api module
     
     var baseUrl = 'http://localhost:9000/api';
     describe('this is description', function () {
     it('this is assert', function (done) {
     Rest.get(baseUrl plus'/testapi/1'). on ('success', function (res) {
     assert(res.result === 1);
     done();
     });
     });
     });

The above is a simple use case for building a nodejs unit test.
A brief description is that the existing mocha framework is used for unit testing, and the gulp integrated test environment is used to configure automated test cases, thus improving efficiency.