Assert

assert.fail(actual, expected, message, operator)
  • v0.1.21
  • Throws an AssertionError. If message is falsy, the error message is set as the values of actual and expected separated by the provided operator. Otherwise, the error message is the value of message
const assert = require('assert');
assert.fail(1, 2, undefined, '>');
 // AssertionError: 1 > 2
assert.fail(1, 2, 'whoops', '>');
assert.ifError(value)
  • v0.1.97
  • Throw value if value is truthy. This is useful when testing the error argument in callbacks.
const assert = require('assert');
assert.ifError(0); // OK
assert.ifError(1); // Throws 1
assert.ifError('error'); // Throws 'error'
assert.ifError(new Error()); // Throws Error
assert.notDeepEqual(actual, expected[, message])
  • v.1.21
    Tests for any deep inequality. Opposite of assert.deepEqual();
const assert = require('assert');
const obj1 = {
    a:{
      b:1
    }
};
const obj2 = {
    a:{
      b:2
    }
};
const obj3 = {
    a:{
      b:1
    }
};
const obj4 = Object.create(obj1);
assert.notDeepEqual(obj1, obj1);
  // AssertionError: { a: { b:1 } } not DeepEqual { a: { b: 1} }
assert.notDeepEqual(obj1, obj2);
  // OK, obj1 and obj2 are not deeply equal
assert.notDeepEqual(obj1, obj3);
  // AssertionError: { a: { b:1 } } not DeepEqual { a: { b: 1} }
assert.notDeepEqual(obj1, obj4); 
// OK, obj1 and obj2 are not deeply equal
assert.notDeepStrictEqual(actual, expected[, message])
assert.ok(value[,message])
assert.notEqual(actual, expected[, message])
assert.notStrictEqual(actual, expected[, message])
assert.ok(value[, message])
assert.strictEqual(actual, expected[, message])
assert.throws(block[, error][, message])

你可能感兴趣的:(Assert)