How to use the expect.assert function in expect

To help you get started, we’ve selected a few expect 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 geowarin / tarec / test / utils / webpack-expect.js View on Github external
function toHandleFile (fileName) {
  const loaders = getLoaders(this.actual);
  const compatibleLoaders = loaders.filter(l => l.regexp.test(fileName));
  expect.assert(
    compatibleLoaders.length < 2,
    '%s is handled by more than one loader: %s',
    fileName,
    compatibleLoaders.map(l => l.name).join(', ')
  );
  expect.assert(
    compatibleLoaders.length === 1,
    '%s is not handled by loaders',
    fileName
  )
}
github ReactTraining / react-history / modules / __tests__ / RenderTestSequences / PromptBlocksAReplace.js View on Github external
() => {
      expect.assert(
        false,
        'A blocked  should not emit a new location'
      )
    }
  ]
github nsmith7989 / redux-filter / test / Filter.spec.js View on Github external
toBeAFunction() {
        expect.assert(
          (typeof this.actual === 'function'),
          'expected %s to be a function',
          this.actual
        );
    }
});
github nsmith7989 / redux-filter / test / Filter.spec.js View on Github external
toBeDefined() {
        expect.assert(
          this.actual !== undefined,
          'expected %s to be defined',
          this.actual
        );
    }
});
github ReactTraining / react-history / modules / __tests__ / RenderTestSequences / PromptBlocksAPush.js View on Github external
() => {
      expect.assert(
        false,
        'A blocked  should not emit a new location'
      )
    }
  ]
github geowarin / tarec / test / utils / webpack-expect.js View on Github external
function toNotHavePlugin (pluginName) {
  const plugins = getPlugins(this.actual);

  const matchingPlugins = plugins.filter(p => p.name == pluginName);
  expect.assert(
    matchingPlugins.length === 0,
    'Plugin %s wasn\'t expected in config',
    pluginName
  );
}
github geowarin / tarec / test / utils / webpack-expect.js View on Github external
function toHavePlugin (pluginName, options) {
  const plugins = getPlugins(this.actual);

  const matchingPlugins = plugins.filter(p => p.name == pluginName);
  expect.assert(
    matchingPlugins.length > 0,
    'No plugin matching %s in %s',
    pluginName,
    plugins.map(p => p.name)
  );
  if (options) {
    var matchingOptions = matchingPlugins.filter(p => matches(p.options, options));
    expect.assert(
      matchingOptions.length > 0,
      'No plugin named %s with options %s in %s',
      pluginName,
      options,
      matchingPlugins.map(p => p.options)
    );
  }
}
function toNotHavePlugin (pluginName) {
github mjackson / expect-element / modules / index.js View on Github external
export function toHaveAttribute(name, value, message) {
  assert(
    isDOMNode(this.actual),
    'The "actual" argument in expect(actual).toHaveAttribute() must be a DOM node, %s was given',
    this.actual
  )

  if (value == null) {
    assert(
      this.actual.getAttribute(name),
      (message || 'Expected %s to have a %s attribute, but it did not'),
      this.actual,
      name
    )
  } else {
    assert(
      this.actual.getAttribute(name) === value,
      (message || 'Expected %s to have a %s attribute of %s, but it was %s'),
      this.actual,
      name,
      value,
      this.actual.getAttribute(name)
    )
  }
}
github mjackson / expect-element / modules / index.js View on Github external
export function toHaveText(text, message) {
  assert(
    isDOMNode(this.actual),
    'The "actual" argument in expect(actual).toHaveText() must be a DOM node, %s was given',
    this.actual
  )

  assert(
    this.actual.textContent === text,
    (message || 'Expected %s to have %s text, but had %s instead'),
    this.actual,
    text,
    this.actual.textContent
  )
}
github mjackson / expect-element / modules / index.js View on Github external
export function toHaveAttribute(name, value, message) {
  assert(
    isDOMNode(this.actual),
    'The "actual" argument in expect(actual).toHaveAttribute() must be a DOM node, %s was given',
    this.actual
  )

  if (value == null) {
    assert(
      this.actual.getAttribute(name),
      (message || 'Expected %s to have a %s attribute, but it did not'),
      this.actual,
      name
    )
  } else {
    assert(
      this.actual.getAttribute(name) === value,
      (message || 'Expected %s to have a %s attribute of %s, but it was %s'),
      this.actual,
      name,
      value,
      this.actual.getAttribute(name)
    )
  }
}

expect

This package exports the `expect` function used in [Jest](https://jestjs.io/). You can find its documentation [on Jest's website](https://jestjs.io/docs/expect).

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis