Check type of object returned from function in Angular 2 Unit Test Case

Solution for Check type of object returned from function in Angular 2 Unit Test Case
is Given Below:

I am new to writing angular unit test. I have 2 methods in a component.

Method 1

    canEnableButton(isButtonEnabled: boolean): boolean {
    return isButtonEnabled || !this.isAvailable;
   }

Method 2

    getObjectValue(): CustomObject {
    if (!this.canEnableButton(this.limit)) {
        return this.CustomValue;
    }
}

I have to write a test case for getObjectValue(). Test case should check whether the function will return the object of type CustomObject or undefined.

First of all you need to configure/mock variable which are used in your methods.
this.isAvailable and this.limit. Since the result of the test is depends on them.

describe('TestComponent', () => {
  let component: TestComponent;
  let fixture: ComponentFixture<TestComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [TestComponent]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(TestComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should return CustomObject', () => {
    component.limit = false;
    component.isAvailable =  true;
    component.customValue = {} as CustomObject;  // you need to mock customValue  related to your CustomObject

    expect(component.getObjectValue()).toEqual(component.customValue);
  });


  it('should return undefined', () => {
    component.limit = true;
    component.isAvailable =  true;
    component.customValue = {} as CustomObject;  // you need to mock customValue  related to your CustomObject

    expect(component.getObjectValue()).toBeUndefined();
  });
  });