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
* Jasmine framework.
*/
import {isPromise} from '../src/facade/lang';
import {isPromise, isString} from '../src/facade/lang';
import {TestInjector, async, getTestInjector, inject, injectAsync} from './test_injector';
@ -108,7 +108,12 @@ function _wrapTestFn(fn: Function) {
let retVal = fn();
if (isPromise(retVal)) {
// 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 {
// Synchronous test function - complete immediately.
done();

View File

@ -142,7 +142,8 @@ export function main() {
itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); },
(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();
});
restoreJasmineIt();

View File

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