Skip to content

⬅️ Back to Table of Contents

📄 mock/assert

📊 Analysis Summary

Metric Count
🔧 Functions 2
🧱 Classes 1

📚 Table of Contents

🛠️ File Location:

📂 packages/website-eslint/src/mock/assert.js

Functions

fail(actual: any, expected: any, message: any, operator: any, stackStartFunction: any): void

Parameters:

  • actual any
  • expected any
  • message any
  • operator any
  • stackStartFunction any

Returns: void

Code
function fail(actual, expected, message, operator, stackStartFunction) {
  throw new AssertionError({
    actual,
    expected,
    message,
    operator,
    stackStartFunction,
  });
}

assert(value: any, message: any): void

Parameters:

  • value any
  • message any

Returns: void

Calls:

  • fail
Code
function assert(value, message) {
  if (!value) {
    fail(value, true, message, '==', assert);
  }
}

Classes

AssertionError

Extends: Error

Class Code
class AssertionError extends Error {
  constructor(options) {
    super(options);

    this.actual = options.actual;
    this.expected = options.expected;
    this.operator = options.operator;
    if (options.message) {
      this.message = options.message;
      this.generatedMessage = false;
    } else {
      this.message = '';
      this.generatedMessage = true;
    }
    const stackStartFunction = options.stackStartFunction || fail;
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, stackStartFunction);
    } else {
      // non v8 browsers so we can have a stacktrace
      const err = new Error();
      if (err.stack) {
        let out = err.stack;

        // try to strip useless frames
        const fn_name =
          typeof stackStartFunction === 'function'
            ? stackStartFunction.name
            : stackStartFunction.toString();
        const idx = out.indexOf(`\n${fn_name}`);
        if (idx >= 0) {
          // once we have located the function frame
          // we need to strip out everything before it (and its line)
          const next_line = out.indexOf('\n', idx + 1);
          out = out.substring(next_line + 1);
        }

        this.stack = out;
      }
    }
  }
}

Generated by Syntax Scribe