I have a unit test as below
it('billing information is correct', () => {
fixture.detectChanges();
spyOn(component.myEventEmitter, 'emit').and.callThrough();
component.form.controls['size'].setValue(12);
fixture.detectChanges();
**let args= component.myEventEmitter.emit.mostRecentCall **
expect(args.billingSize).toEqual('30')
});
When size changes, myEventEmitter is being emitted with a large json object which includes billingSize. And I want the test to check if this value is as expected. But looks like I can't do 'mostRecentCall/ calls' on the event emitter. any suggestions??
Note: I don't want to do
expect(component.myEventEmitter.emit).toHaveBeenCalledWith(*dataExpected*);
because the dataExpected is a large json object. I just care about one field. Any help would be much appreciated.
This should work.
it('billing information is correct', () => {
fixture.detectChanges();
spyOn(component.myEventEmitter, 'emit').and.callThrough();
component.form.controls['size'].setValue(12);
fixture.detectChanges();
let arg: any = (component.myEventEmitter.emit as any).calls.mostRecent().args[0];
expect(arg.billingSize).toEqual('30');
});
note:
component.myEventEmitter.emit.calls.mostRecent()
- wouldn't compile (error: calls does not exist on type ..') so type it to 'any' and should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With