How to use the qunit.assert function in qunit

To help you get started, we’ve selected a few qunit 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 emberjs / data / packages / unpublished-test-infra / addon-test-support / watch-property.js View on Github external
// this allows us to handle watchers passed in from a watchProperties return hash
  if (!watcher.counter && watcher.count !== undefined) {
    counter = watcher;
  } else {
    counter = watcher.counter;
  }

  this.pushResult({
    result: counter.count === expectedCount,
    actual: counter.count,
    expected: expectedCount,
    message: label,
  });
};

QUnit.assert.dirties = function assertDirties(options, updateMethodCallback, label) {
  let { object: obj, property, count } = options;
  count = typeof count === 'number' ? count : 1;
  let { counter, unwatch } = watchProperty(obj, property);
  updateMethodCallback();
  this.pushResult({
    result: counter.count === count,
    actual: counter.count,
    expected: count,
    message: label,
  });
  unwatch();
};
github emberjs / data / packages / unpublished-test-infra / addon-test-support / qunit-asserts / assert-deprecation.ts View on Github external
HAS_REGISTERED = true;

  QUnit.testStart(function() {
    DEPRECATIONS_FOR_TEST = [];
    HANDLED_DEPRECATIONS_FOR_TEST = [];
  });

  registerDeprecationHandler(function(message, options: DeprecationConfig /*, next*/) {
    options.stacktrace = new Error().stack;
    if (DEPRECATIONS_FOR_TEST) {
      DEPRECATIONS_FOR_TEST.push({ message, options });
    }
    // we do not call next to avoid spamming the console
  });

  QUnit.assert.expectDeprecation = async function(
    cb: () => unknown,
    config: string | RegExp | DeprecationConfig,
    label?: string
  ): Promise {
    let origDeprecations = DEPRECATIONS_FOR_TEST;
    let callback: (() => unknown) | null = null;

    if (typeof cb !== 'function') {
      config = cb;
      callback = null;
    } else {
      callback = cb;
    }

    if (typeof config === 'string' || config instanceof RegExp) {
      config = {
github workmanw / ember-qunit-assert-helpers / addon-test-support / asserts / assertion.js View on Github external
export default function() {
  let isProductionBuild = (function() {
    try {
      Ember.assert('fails in debug builds');
    } catch(e) {
      return false;
    }

    return true;
  })();

  QUnit.assert.expectAssertion = function(cb, matcher) {
    // Save off the original adapter and replace it with a test one.
    let origTestAdapter = Ember.Test.adapter;
    let origLoggerError = Ember.Logger.error;
    Ember.run(() => {
      Ember.Test.adapter = TestAdapter.create();
      Ember.Logger.error = noop;
    });

    let error = null;
    try {
      cb();
    } catch (e) {
      error = e;
    } finally {
      error = error || Ember.Test.adapter.lastError;
    }
github videojs / http-streaming / test / custom-assertions.js View on Github external
export const bandwidthWithinTolerance = function(actual, expected, message) {
  QUnit.assert.ok(
    Math.abs(actual - expected) < (expected * BANDWIDTH_TOLERANCE),
    `${message}: expected ${actual} to be within ${BANDWIDTH_TOLERANCE} of ${expected}`
  );
};
github elwayman02 / ember-data-github / tests / helpers / custom-helpers / assert-github-tree-ok.js View on Github external
import { registerHelper } from '@ember/test';
import QUnit from 'qunit';
import assertionBuilder from '../utils/defined-attribute-assertion-builder';

QUnit.assert.githubTreeOk = assertionBuilder([
  'id',
  'sha',
  'url',
  'files',
  'directories',
  'blobs',
  'trees',
  'truncated'
]);

export default registerHelper(
  'assertGithubTreeOk',
  function (app, assert, tree) {
    assert.githubTreeOk(tree);
  }
);
github elwayman02 / ember-data-github / tests / helpers / custom-helpers / assert-github-user-ok.js View on Github external
import { registerHelper } from '@ember/test';
import QUnit from 'qunit';
import assertionBuilder from '../utils/defined-attribute-assertion-builder';

QUnit.assert.githubUserOk = assertionBuilder([
  'id',
  'login',
  'name',
  'type',
  'avatarUrl',
  'publicRepos',
  'publicGists',
  'followers',
  'following',
  'createdAt',
  'updatedAt',
  'url'
]);

export default registerHelper(
  'assertGithubUserOk',
github emberjs / data / packages / unpublished-test-infra / addon-test-support / qunit-asserts / assert-assertion.ts View on Github external
outcome = verifyAssertion(e.message, matcher, label);
    }

    if (!DEBUG) {
      outcome = {
        result: true,
        actual: '',
        expected: '',
        message: `Assertions do not run in production environments`,
      };
    }

    this.pushResult(outcome);
  };

  QUnit.assert.expectNoAssertion = async function(cb: () => unknown, label?: string) {
    let outcome;
    try {
      let result = cb();
      if (isThenable(result)) {
        await result;
      }
      outcome = verifyNoAssertion('', label);
    } catch (e) {
      outcome = verifyNoAssertion(e.message, label);
    }

    if (!DEBUG) {
      outcome = {
        result: true,
        actual: '',
        expected: '',
github code-corps / code-corps-ember / tests / helpers / has-attributes.js View on Github external
It first convert the attributes Map to an Array,
  then sorts both arrays and then compares each element.

  @method hasAttributes
  @param {Map} actualAttributes
  @param {Array} expectedAttributes
*/
function compareArrays(actualAttributes, expectedAttributes) {
  expectedAttributes.sort();

  return actualAttributes.sort().every(function(element, index) {
    return element === expectedAttributes[index];
  });
}

QUnit.assert.hasAttributes = function(actualAttributes, expectedAttributes) {
  this.expect(2);

  let actualAttributesArray = [];
  actualAttributes.forEach(function(meta, name) {
    actualAttributesArray.push(name);
  });

  this.ok(actualAttributesArray.length === expectedAttributes.length, `should have ${expectedAttributes.length} attributes`);
  this.ok(compareArrays(actualAttributesArray, expectedAttributes), 'should have the expected attributes');
};
github videojs / http-streaming / test / custom-assertions.js View on Github external
export const timeRangesEqual = function(timeRange1, timeRange2, message) {
  QUnit.assert.deepEqual(timeRangesToArray(timeRange1), timeRangesToArray(timeRange2), message);
};
github emberjs / data / packages / -ember-data / node-tests / docs / test-coverage.js View on Github external
function buildDocs() {
  let child = require('child_process');
  child.execFileSync('node', [require.resolve('ember-cli/bin/ember'), 'ember-cli-yuidoc'], {
    stdio: 'pipe',
  });
}

function setDifference(setA, setB) {
  let difference = new Set(setA);
  for (var elem of setB) {
    difference.delete(elem);
  }
  return difference;
}

QUnit.assert.emptySet = function assertEmptySet(value, message) {
  this.pushResult({
    result: value.size === 0,
    actual: Array.from(value).sort(),
    expected: [],
    message: message,
  });
};