https://mochajs.org/#installation
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on GitHub.
https://nodejs.org/api/assert.html
- assert(value[, message])
- assert.deepEqual(actual, expected[, message])
- assert.doesNotReject(block[, error][, message])
- assert.doesNotThrow(block[, error][, message])
- assert.equal(actual, expected[, message])
- assert.fail([message])
- assert.fail(actual, expected[, message[, operator[, stackStartFunction]]])
- assert.ifError(value)
- assert.notDeepEqual(actual, expected[, message])
- assert.notDeepStrictEqual(actual, expected[, message])
- assert.notEqual(actual, expected[, message])
- assert.notStrictEqual(actual, expected[, message])
- assert.ok(value[, message])
- assert.rejects(block[, error][, message])
- assert.strictEqual(actual, expected[, message])
- assert.throws(block[, error][, message])
https://github.com/fanqingsong/code-snippet/tree/master/web/mocha_test
var assert = require(‘assert‘); describe(‘Array‘, function() { describe(‘#indexOf()‘, function() { it(‘should return -1 when the value is not present‘, function() { assert.equal([1,2,3].indexOf(4), -1); }); }); });
原文:https://www.cnblogs.com/lightsong/p/9452464.html