Angular: Unit test that a component's output is not emitted
You can use a spy like this:
describe('ExampleComponent', () => {
it('should not output duplicate values', () => {
const component = new ExampleComponent();
spyOn(component.output, 'emit');
component.value = 1;
component.onValueChange(1);
expect(component.output.emit).not.toHaveBeenCalled();
});
});
That's pretty much how you do it. A variation is:
describe('ExampleComponent', () => {
it('should not output duplicate values', () => {
const component = new ExampleComponent();
let numEvents = 0;
component.value = 1;
component.output.subscribe(value => ++numEvents);
component.onValueChange(1);
expect(numEvents).toEqual(0);
});
});