I'm trying to test the output of a Subject symbol$ that exists on my component.
Specifically, Subject symbol$ should emit (is this the right word here?) a value whenever the component property symbol has changed.
However, I could not find a way to test the output to symbol$ until I came across a chunk of code online that uses the .subscribe(next() { ... }) instead of .subscribe((x) => {...}); syntax.
What is the difference between the 2 calls? And why does only 1 of these work?
it('should fetch data', () => {
const actuals: string[] = [];
// commented version doesn't work
// component.symbol$.subscribe((symbol) => { actuals.push(symbol); } ;
component.symbol$.subscribe({
next(symbol) {
actuals.push(symbol);
},
});
expect(actuals).toEqual(['']);
component.symbol = 'IBM';
component.ngOnChanges();
expect(actuals).toEqual(['', 'IBM']);
});

