fix(core/testing): show full error

test(platform-browser): update fail capture

test(platform-browser-dynamic): update fail capture
This commit is contained in:
PatrickJS 2016-06-20 17:54:12 -07:00 committed by Victor Berchet
parent 86405345b7
commit 297f0fd2c3
3 changed files with 13 additions and 6 deletions

View File

@ -2,7 +2,7 @@
* Public Test Library for unit testing Angular2 Applications. Uses the * Public Test Library for unit testing Angular2 Applications. Uses the
* Jasmine framework. * Jasmine framework.
*/ */
import {isPromise} from '../src/facade/lang'; import {isPromise, isString} from '../src/facade/lang';
import {TestInjector, async, getTestInjector, inject, injectAsync} from './test_injector'; import {TestInjector, async, getTestInjector, inject, injectAsync} from './test_injector';
@ -108,7 +108,12 @@ function _wrapTestFn(fn: Function) {
let retVal = fn(); let retVal = fn();
if (isPromise(retVal)) { if (isPromise(retVal)) {
// Asynchronous test function - wait for completion. // Asynchronous test function - wait for completion.
(<Promise<any>>retVal).then(done, done.fail); (<Promise<any>>retVal).then(done, (err) => {
if (isString(err)) {
return done.fail(new Error(err));
}
return done.fail(err);
});
} else { } else {
// Synchronous test function - complete immediately. // Synchronous test function - complete immediately.
done(); done();

View File

@ -142,7 +142,8 @@ export function main() {
itPromise.then( itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); }, () => { done.fail('Expected test to fail, but it did not'); },
(err) => { (err) => {
expect(err).toEqual('Uncaught (in promise): Failed to load non-existant.html'); expect(err.message)
.toEqual('Uncaught (in promise): Failed to load non-existant.html');
done(); done();
}); });
restoreJasmineIt(); restoreJasmineIt();

View File

@ -231,14 +231,15 @@ export function main() {
it('should fail when an asynchronous error is thrown', (done: any /** TODO #9100 */) => { it('should fail when an asynchronous error is thrown', (done: any /** TODO #9100 */) => {
var itPromise = patchJasmineIt(); var itPromise = patchJasmineIt();
var barError = new Error('bar');
it('throws an async error', it('throws an async error',
async(inject([], () => { setTimeout(() => { throw new Error('bar'); }, 0); }))); async(inject([], () => { setTimeout(() => { throw barError; }, 0); })));
itPromise.then( itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); }, () => { done.fail('Expected test to fail, but it did not'); },
(err) => { (err) => {
expect(err).toEqual('bar'); expect(err).toEqual(barError);
done(); done();
}); });
restoreJasmineIt(); restoreJasmineIt();
@ -258,7 +259,7 @@ export function main() {
itPromise.then( itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); }, () => { done.fail('Expected test to fail, but it did not'); },
(err) => { (err) => {
expect(err).toEqual('Uncaught (in promise): baz'); expect(err.message).toEqual('Uncaught (in promise): baz');
done(); done();
}); });
restoreJasmineIt(); restoreJasmineIt();