Esempio n. 1
0
QUnit.test('rejections can be serialized to JSON', function (assert) {
  expect(2);

  let wasEmberTesting = isTesting();
  let wasOnError      = getOnerror();

  try {
    setTesting(false);
    setOnerror(error => {
      assert.equal(error.message, 'a fail');
      assert.ok(JSON.stringify(error), 'Error can be serialized');
    });

    let jqXHR = {
      errorThrown: new Error('a fail')
    };

    run(RSVP, 'reject', jqXHR);
  } finally {
    setOnerror(wasOnError);
    setTesting(wasEmberTesting);
  }
});
Esempio n. 2
0
QUnit.test('rejections where the errorThrown is a string should wrap the sting in an error object', function() {
  expect(2);

  let wasEmberTesting = isTesting();
  let wasOnError      = getOnerror();

  try {
    setTesting(false);
    setOnerror(error => {
      equal(error.message, actualError, 'expected the real error on the jqXHR');
      equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
    });

    let actualError = 'OMG what really happened';
    let jqXHR = {
      errorThrown: actualError
    };

    run(RSVP, 'reject', jqXHR);
  } finally {
    setOnerror(wasOnError);
    setTesting(wasEmberTesting);
  }
});
Esempio n. 3
0
QUnit.test('rejections like jqXHR which have errorThrown property work', function() {
  expect(2);

  let wasEmberTesting = isTesting();
  let wasOnError      = getOnerror();

  try {
    setTesting(false);
    setOnerror(error => {
      equal(error, actualError, 'expected the real error on the jqXHR');
      equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
    });

    let actualError = new Error('OMG what really happened');
    let jqXHR = {
      errorThrown: actualError
    };

    run(RSVP, 'reject', jqXHR);
  } finally {
    setOnerror(wasOnError);
    setTesting(wasEmberTesting);
  }
});
Esempio n. 4
0
import {
  isTesting,
  setTesting,
  setOnerror,
  getOnerror,
  run
} from 'ember-metal';
import RSVP from '../../ext/rsvp';

const ORIGINAL_ONERROR = getOnerror();

QUnit.module('Ember.RSVP', {
  teardown() {
    setOnerror(ORIGINAL_ONERROR);
  }
});

QUnit.test('Ensure that errors thrown from within a promise are sent to the console', function() {
  let error = new Error('Error thrown in a promise for testing purposes.');

  try {
    run(function() {
      new RSVP.Promise(function(resolve, reject) {
        throw error;
      });
    });
    ok(false, 'expected assertion to be thrown');
  } catch (e) {
    equal(e, error, 'error was re-thrown');
  }
});