mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
It appears that the intent is to return an unlisten function when `on` is called. The message bus implementations indicate that. However, the `MessageBus` abstract class returns `void` instead. Change to `on: () => void`. PR Close #62898
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import {MessageBus} from './message-bus';
|
|
import {Events, Topic} from './messages';
|
|
import {PriorityAwareMessageBus} from './priority-aware-message-bus';
|
|
|
|
class MockMessageBus extends MessageBus<Events> {
|
|
cbs: any = {};
|
|
override emit(_: Topic, __: any): boolean {
|
|
return true;
|
|
}
|
|
override on(topic: Topic, cb: any): () => void {
|
|
this.cbs[topic] = cb;
|
|
return () => {
|
|
delete this.cbs[topic];
|
|
};
|
|
}
|
|
override once(topic: Topic, cb: any): void {
|
|
this.cbs[topic] = cb;
|
|
}
|
|
override destroy(): void {}
|
|
}
|
|
|
|
describe('PriorityAwareMessageBus', () => {
|
|
it('should emit not throttled requests', () => {
|
|
const timeout: any = (_: any, __: number) => {};
|
|
const bus = new PriorityAwareMessageBus(new MockMessageBus(), timeout);
|
|
expect(bus.emit('handshake')).toBeTrue();
|
|
expect(bus.emit('inspectorStart')).toBeTrue();
|
|
});
|
|
|
|
it('should throttle `getLatestComponentExplorerView`', () => {
|
|
let callback: any;
|
|
const timeout: any = (cb: any, _: number) => {
|
|
callback = cb;
|
|
};
|
|
const bus = new PriorityAwareMessageBus(new MockMessageBus(), timeout);
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeTrue();
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeFalse();
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeFalse();
|
|
callback();
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeTrue();
|
|
});
|
|
|
|
it('should not emit `getLatestComponentExplorerView` if blocked by `getNestedProperties`', () => {
|
|
let callback: any;
|
|
const timeout: any = (cb: any, _: number) => {
|
|
callback = cb;
|
|
};
|
|
const mock = new MockMessageBus();
|
|
const bus = new PriorityAwareMessageBus(mock, timeout);
|
|
bus.on('nestedProperties', () => {});
|
|
expect(bus.emit('getNestedProperties')).toBeTrue();
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeFalse();
|
|
mock.cbs.nestedProperties();
|
|
expect(bus.emit('getLatestComponentExplorerView')).toBeTruthy();
|
|
});
|
|
});
|