Unit test recipes (Jasmine / Karma / Angular)

Test a component emission

describe('emitChange', () => {
  it('should emit the ipn changed', () => {
    spyOn(component.ipnChanged, 'emit');
    component.emitChange('p092354');
    expect(component.ipnChanged.emit).toHaveBeenCalledWith('p092354');
  });
});

Test a form initialization

describe('ngOnInit', () => {
  it('should initialize the form with approval IPN', () => {
     const testIpn = '55352sss';
     component.approval = { ipn: testIPN};
     component.ngOnInit();
     expect(component.ipnForm.value.ipn).toBe(testIPN);
  });
});

Test the afterClosed function of a mat dialog

Last updated