Issue
is it possible to test if eventAggregator.publish was executed during another publish?
this.eventAggregator.with(this).subscribe(Xevent, (event: Xevent) => {
this.eventAggregator.publish(new anotherEvent());
});
If I test it like this:
describe('when X event is published', () => {
it('then Y event should be published', () => {
//arrange
let event = new Xevent();
spyOn(evtAggregator, 'publish');
//act
evtAggregator.publish(event);
//assert
expect(evtAggregator.publish).toHaveBeenCalledWith(new anotherEvent());
});
});
jasmine gives me an error that event Aggregator was called with "Xevent":
Expected spy publish to have been called with [ anotherEvent ... ] but actual calls were [ Xevent ...]
Can I assert it a different way or am I something missing in arrange section?
Solution
I had to add ".and.callThrough()" for spy:
describe('when X event is published', () => {
it('then Y event should be published', () => {
//arrange
let event = new Xevent();
spyOn(evtAggregator, 'publish').and.callThrough(); //here is the change
//act
evtAggregator.publish(event);
//assert
expect(evtAggregator.publish).toHaveBeenCalledWith(new anotherEvent());
});
});
Simpler than I thought.
Answered By - Patryk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.