How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import assert from 'assert/strict';
    
    assert.ifError(null);
    // OK
    assert.ifError(0);
    // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
    assert.ifError('error');
    // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
    assert.ifError(new Error());
    // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
    
    // Create some random error frames.
    let err;
    (function errorFrame() {
      err = new Error('test error');
    })();
    
    (function ifErrorFrame() {
      assert.ifError(err);
    })();
    // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
    //     at ifErrorFrame
    //     at errorFrame
    Docs
  • const assert = require('assert/strict');
    
    assert.rejects(
      Promise.reject(new Error('Wrong value')),
      Error
    ).then(() => {
      // ...
    });
    Docs
  • const assert = require('assert');
    
    // Generate an AssertionError to compare the error message later:
    const { message } = new assert.AssertionError({
      actual: 1,
      expected: 2,
      operator: 'strictEqual'
    });
    
    // Verify error output:
    try {
      assert.strictEqual(1, 2);
    } catch (err) {
      assert(err instanceof assert.AssertionError);
      assert.strictEqual(err.message, message);
      assert.strictEqual(err.name, 'AssertionError');
      assert.strictEqual(err.actual, 1);
      assert.strictEqual(err.expected, 2);
      assert.strictEqual(err.code, 'ERR_ASSERTION');
      assert.strictEqual(err.operator, 'strictEqual');
      assert.strictEqual(err.generatedMessage, true);
    }
    Docs
  • const assert = require('assert/strict');
    
    assert.throws(
      () => {
        throw new Error('Wrong value');
      },
      Error
    );
    Docs
  • import assert from 'assert/strict';
    
    assert.rejects(
      Promise.reject(new Error('Wrong value')),
      Error
    ).then(() => {
      // ...
    });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples