fix(facade): change EventEmitter to be sync by default (#8761)
This commit is contained in:
parent
cf1122cf9e
commit
e5904f4089
|
@ -1527,11 +1527,10 @@ function declareTests(isJit: boolean) {
|
|||
tick();
|
||||
|
||||
var tc = fixture.debugElement.children[0];
|
||||
tc.inject(DirectiveEmittingEvent).fireEvent("boom");
|
||||
|
||||
|
||||
try {
|
||||
tick();
|
||||
throw "Should throw";
|
||||
tc.inject(DirectiveEmittingEvent).fireEvent("boom");
|
||||
} catch (e) {
|
||||
clearPendingTimers();
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ export class EventEmitter<T> extends Subject<T> {
|
|||
* Creates an instance of [EventEmitter], which depending on [isAsync],
|
||||
* delivers events synchronously or asynchronously.
|
||||
*/
|
||||
constructor(isAsync: boolean = true) {
|
||||
constructor(isAsync: boolean = false) {
|
||||
super();
|
||||
this.__isAsync = isAsync;
|
||||
}
|
||||
|
|
|
@ -46,27 +46,27 @@ export function main() {
|
|||
ObservableWrapper.callComplete(emitter);
|
||||
}));
|
||||
|
||||
it("should subscribe to the wrapper asynchronously", () => {
|
||||
it("should subscribe to the wrapper synchronously", () => {
|
||||
var called = false;
|
||||
ObservableWrapper.subscribe(emitter, (value) => { called = true; });
|
||||
|
||||
ObservableWrapper.callEmit(emitter, 99);
|
||||
expect(called).toBe(false);
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
// Makes Edge to disconnect when running the full unit test campaign
|
||||
// TODO: remove when issue is solved: https://github.com/angular/angular/issues/4756
|
||||
if (!browserDetection.isEdge) {
|
||||
it("delivers next and error events asynchronously", inject([AsyncTestCompleter], (async) => {
|
||||
it("delivers next and error events synchronously", inject([AsyncTestCompleter], (async) => {
|
||||
let log = [];
|
||||
ObservableWrapper.subscribe(emitter,
|
||||
(x) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 5, 2]);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
(err) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 3, 5, 2, 4]);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
async.done();
|
||||
});
|
||||
log.push(1);
|
||||
|
@ -76,36 +76,39 @@ export function main() {
|
|||
log.push(5);
|
||||
}));
|
||||
|
||||
it("delivers next and complete events asynchronously",
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
it("delivers next and complete events synchronously", () => {
|
||||
let log = [];
|
||||
ObservableWrapper.subscribe(emitter,
|
||||
(x) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 5, 2]);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
null, () => {
|
||||
log.push(4);
|
||||
expect(log).toEqual([1, 3, 5, 2, 4]);
|
||||
async.done();
|
||||
});
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
log.push(1);
|
||||
ObservableWrapper.callEmit(emitter, 2);
|
||||
log.push(3);
|
||||
ObservableWrapper.callComplete(emitter);
|
||||
log.push(5);
|
||||
}));
|
||||
expect(log).toEqual([1, 2, 3, 4, 5]);
|
||||
});
|
||||
}
|
||||
|
||||
it('delivers events synchronously', () => {
|
||||
var e = new EventEmitter(false);
|
||||
it('delivers events asynchronously when forced to async mode', inject([AsyncTestCompleter], (async) => {
|
||||
var e = new EventEmitter(true);
|
||||
var log = [];
|
||||
ObservableWrapper.subscribe(e, (x) => { log.push(x); });
|
||||
ObservableWrapper.subscribe(e, (x) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 2]);
|
||||
async.done();
|
||||
});
|
||||
log.push(1);
|
||||
ObservableWrapper.callEmit(e, 2);
|
||||
log.push(3);
|
||||
expect(log).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('reports whether it has subscribers', () => {
|
||||
var e = new EventEmitter(false);
|
||||
|
|
|
@ -44,11 +44,12 @@ export function main() {
|
|||
});
|
||||
|
||||
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
|
||||
locationStrategy.simulatePopState('/my/app/user/btford');
|
||||
|
||||
location.subscribe((ev) => {
|
||||
expect(ev['url']).toEqual('/user/btford');
|
||||
async.done();
|
||||
})
|
||||
});
|
||||
locationStrategy.simulatePopState('/my/app/user/btford');
|
||||
}));
|
||||
|
||||
it('should revert to the previous path when a back() operation is executed', () => {
|
||||
|
|
|
@ -193,19 +193,11 @@ export function main() {
|
|||
expect(multiTrim(document.body.textContent))
|
||||
.toEqual(
|
||||
"ignore: -; " + "literal: Text; interpolate: Hello world; " +
|
||||
"oneWayA: A; oneWayB: B; twoWayA: initModelA; twoWayB: initModelB; (1) | " +
|
||||
"modelA: initModelA; modelB: initModelB; eventA: ?; eventB: ?;");
|
||||
setTimeout(() => {
|
||||
// we need to do setTimeout, because the EventEmitter uses setTimeout to schedule
|
||||
// events, and so without this we would not see the events processed.
|
||||
expect(multiTrim(document.body.textContent))
|
||||
.toEqual("ignore: -; " + "literal: Text; interpolate: Hello world; " +
|
||||
"oneWayA: A; oneWayB: B; twoWayA: newA; twoWayB: newB; (3) | " +
|
||||
"modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;");
|
||||
ref.dispose();
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
"oneWayA: A; oneWayB: B; twoWayA: newA; twoWayB: newB; (2) | " +
|
||||
"modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;")
|
||||
ref.dispose();
|
||||
async.done();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in New Issue