feat(AsyncPipe): allow onError argument

Closes #7990
This commit is contained in:
gdi2290
2016-04-08 18:14:46 -07:00
committed by Misko Hevery
parent 587c119c75
commit 390046d7b3
2 changed files with 59 additions and 26 deletions

View File

@ -52,10 +52,9 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(pipe.transform(emitter)).toEqual(new WrappedValue(message));
async.done();
}, 0)
}, 0);
}));
it("should return same value when nothing has changed since the last call",
inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
@ -65,7 +64,23 @@ export function main() {
pipe.transform(emitter);
expect(pipe.transform(emitter)).toBe(message);
async.done();
}, 0)
}, 0);
}));
it("should invoke onError of when a function is provided",
inject([AsyncTestCompleter], (async) => {
var error = false;
function onError() { error = true; }
expect(() => pipe.transform(emitter, onError)).not.toThrow();
expect(error).toBe(false);
// this should not affect the pipe
ObservableWrapper.callError(emitter, message);
TimerWrapper.setTimeout(() => {
expect(error).toBe(true);
async.done();
}, 0);
}));
it("should dispose of the existing subscription when subscribing to a new observable",
@ -81,7 +96,7 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(pipe.transform(newEmitter)).toBe(null);
async.done();
}, 0)
}, 0);
}));
it("should request a change detection check upon receiving a new value",
@ -92,7 +107,7 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(ref.spy('markForCheck')).toHaveBeenCalled();
async.done();
}, 10)
}, 10);
}));
});
@ -109,7 +124,7 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(pipe.transform(emitter)).toBe(null);
async.done();
}, 0)
}, 0);
}));
});
});
@ -140,7 +155,23 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
async.done();
}, timer)
}, timer);
}));
it("should invoke onError of when a function is provided",
inject([AsyncTestCompleter], (async) => {
var error = false;
function onError() { error = true; }
expect(() => pipe.transform(completer.promise, onError)).not.toThrow();
expect(error).toBe(false);
// this should not affect the pipe
completer.reject('rejection');
TimerWrapper.setTimeout(() => {
expect(error).toBe(true);
async.done();
}, 0);
}));
it("should return unwrapped value when nothing has changed since the last call",
@ -152,7 +183,7 @@ export function main() {
pipe.transform(completer.promise);
expect(pipe.transform(completer.promise)).toBe(message);
async.done();
}, timer)
}, timer);
}));
it("should dispose of the existing subscription when subscribing to a new promise",
@ -168,7 +199,7 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(pipe.transform(newCompleter.promise)).toBe(null);
async.done();
}, timer)
}, timer);
}));
it("should request a change detection check upon receiving a new value",
@ -180,7 +211,7 @@ export function main() {
TimerWrapper.setTimeout(() => {
expect(markForCheck).toHaveBeenCalled();
async.done();
}, timer)
}, timer);
}));
describe("ngOnDestroy", () => {
@ -190,15 +221,15 @@ export function main() {
it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => {
pipe.transform(completer.promise);
expect(pipe.transform(completer.promise)).toBe(null);
completer.resolve(message)
completer.resolve(message);
TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
pipe.ngOnDestroy();
expect(pipe.transform(completer.promise)).toBe(null);
async.done();
}, timer);
TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
pipe.ngOnDestroy();
expect(pipe.transform(completer.promise)).toBe(null);
async.done();
}, timer);
}));
});
});