How to use assertion-error - 6 common examples

To help you get started, we’ve selected a few assertion-error examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kimjoar / expect-to / src / index.js View on Github external
let { expected, msg } = res
    const showDiff = expected !== undefined

    if (showDiff) {
      // if the error starts with "expected" and we can show a diff,
      // then prefix the error message with `\w+: expected` (lower-case e)
      // and mocha will drop everything after the :
      // https://github.com/mochajs/mocha/blob/c0f9be244bff479e948f59d1bdb825a45c2cb40c/lib/reporters/base.js#L208-L209

      if (msg.match(/^expected /i)) {
        msg = `expect-to assertion failure: expected ${msg.slice(9)}`
      }
    }

    throw new AssertionError(msg, { showDiff, actual, expected })
  }
}
github etiennedi / enzyme-wait / src / index.js View on Github external
export const createWaitForElement = (selector, maxTime = 2000, interval = 10) => rootComponent => {

  // Check correct usage
  if (!selector) {
    return Promise.reject(new AssertionError(`No selector specified in ${DISPLAY_NAME}.`));
  }

  if (!rootComponent) {
    return Promise.reject(new AssertionError(`No root component specified in ${DISPLAY_NAME}.`));
  }

  if (!rootComponent.length) {
    return Promise.reject(new AssertionError(`Specified root component in ${DISPLAY_NAME} not found.`));
  }


  // Race component search against maxTime
  return new Promise((resolve, reject) => {

    let remainingTime = maxTime;

    const intervalId = setInterval(() => {
      if (remainingTime < 0) {
        clearInterval(intervalId);
        return reject(new AssertionError(`Expected to find ${selector} within ${maxTime}ms, but it was never found.`))
      }

      const targetComponent = rootComponent.update().find(selector);
      if (targetComponent.length) {
github mmiller42 / html-webpack-externals-plugin / test / HtmlWebpackExternalsPlugin.spec.js View on Github external
.then(() =>
            reject(new AssertionError('Plugin should not have copied jQuery'))
          )
github mmiller42 / html-webpack-externals-plugin / test / HtmlWebpackExternalsPlugin.spec.js View on Github external
.then(() =>
            reject(new AssertionError('Plugin should not have injected jQuery'))
          )
github mmiller42 / html-webpack-externals-plugin / test / HtmlWebpackExternalsPlugin.spec.js View on Github external
.then(() =>
            reject(new AssertionError('Plugin should not have excluded jQuery'))
          )
github mmiller42 / html-webpack-externals-plugin / test / HtmlWebpackExternalsPlugin.spec.js View on Github external
.then(() =>
              reject(
                new AssertionError(
                  'index.html should not have had the assets inserted into the HTML'
                )
              )
            )

assertion-error

Error constructor for test and validation frameworks that implements standardized AssertionError specification.

MIT
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis

Popular assertion-error functions