Jasmine tests for tax calculations in Angular 4

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I am writing Jasmine tests in an Angular application and need to verify if I am testing correctly. If not, I would like suggestions in what area I should actually test.



If you see in the code, harness.fedExciseExpensesInputs is test data created by me. It's like mocking the actual data. The property returns a filtered value if currentSelectedCoveragePolicy is not equal to zero, else it will return _fedExTax which is defined in the declarations.



Here is the property in the component that I am testing called fedExTax:



Component code:



@Input() fedExciseExpensesInputs: Array<BackendDto.FedExciseExpense>;
@Input() currentSelectedCurrency: string;
@Input() currentSelectedCoveragePolicy: number;
@Input() currentSelected953D: number;
private _fedExTax: BackendDto.FedExciseExpense = value: 0, coveragePolicyTypeId: null, is953D: null ;

get fedExTax(): BackendDto.FedExciseExpense
if (this.currentSelectedCoveragePolicy !== 0)
this.isReadOnly = false;
return this.fedExciseExpensesInputs.find(x => x.coveragePolicyTypeId === this.currentSelectedCoveragePolicy && x.is953D === this.currentSelected953D);
else
this.isReadOnly = true;
return this._fedExTax;




Test code:



 beforeEach(() => 
fixture = TestBed.createComponent(HostFormTestComponent);
harness = fixture.componentInstance;
fixture.detectChanges();
sut = harness.componentUnderTest;
harness.incrementalExpensesInputs = IncrementalExpenses;
harness.fedExciseExpensesInputs = fedExciseTaxExpenses;
fixture.detectChanges();
);

it('should set fields correctly when currentSelectedCoveragePolicy is 0', () =>
sut.fedExTax.coveragePolicyTypeId = 0;
fixture.detectChanges();
//expect(sut.fedExTax.coveragePolicyTypeId).toBeNull();
expect(sut.fedExciseExpensesInputs).toBeNull();
);

it('should set fields correctly when currentSelectedCoveragePolicy is 1', () =>
sut.currentSelectedCoveragePolicy = 1;
fixture.detectChanges();
expect(sut.fedExciseExpensesInputs[0].coveragePolicyTypeId).toEqual(1);
//expect(sut.fedExTax.coveragePolicyTypeId).toEqual(1);
);


export const createFedExciseExpenses = (): Array<BackendDto.FedExciseExpense> =>
return [
is953D : 1, coveragePolicyTypeId : 1, value : 0,
is953D : 0, coveragePolicyTypeId : 1, value : 1,
is953D : 0, coveragePolicyTypeId : 2, value : 4,
is953D : 1, coveragePolicyTypeId : 2, value : 0
];
;






share|improve this question



























    up vote
    0
    down vote

    favorite












    I am writing Jasmine tests in an Angular application and need to verify if I am testing correctly. If not, I would like suggestions in what area I should actually test.



    If you see in the code, harness.fedExciseExpensesInputs is test data created by me. It's like mocking the actual data. The property returns a filtered value if currentSelectedCoveragePolicy is not equal to zero, else it will return _fedExTax which is defined in the declarations.



    Here is the property in the component that I am testing called fedExTax:



    Component code:



    @Input() fedExciseExpensesInputs: Array<BackendDto.FedExciseExpense>;
    @Input() currentSelectedCurrency: string;
    @Input() currentSelectedCoveragePolicy: number;
    @Input() currentSelected953D: number;
    private _fedExTax: BackendDto.FedExciseExpense = value: 0, coveragePolicyTypeId: null, is953D: null ;

    get fedExTax(): BackendDto.FedExciseExpense
    if (this.currentSelectedCoveragePolicy !== 0)
    this.isReadOnly = false;
    return this.fedExciseExpensesInputs.find(x => x.coveragePolicyTypeId === this.currentSelectedCoveragePolicy && x.is953D === this.currentSelected953D);
    else
    this.isReadOnly = true;
    return this._fedExTax;




    Test code:



     beforeEach(() => 
    fixture = TestBed.createComponent(HostFormTestComponent);
    harness = fixture.componentInstance;
    fixture.detectChanges();
    sut = harness.componentUnderTest;
    harness.incrementalExpensesInputs = IncrementalExpenses;
    harness.fedExciseExpensesInputs = fedExciseTaxExpenses;
    fixture.detectChanges();
    );

    it('should set fields correctly when currentSelectedCoveragePolicy is 0', () =>
    sut.fedExTax.coveragePolicyTypeId = 0;
    fixture.detectChanges();
    //expect(sut.fedExTax.coveragePolicyTypeId).toBeNull();
    expect(sut.fedExciseExpensesInputs).toBeNull();
    );

    it('should set fields correctly when currentSelectedCoveragePolicy is 1', () =>
    sut.currentSelectedCoveragePolicy = 1;
    fixture.detectChanges();
    expect(sut.fedExciseExpensesInputs[0].coveragePolicyTypeId).toEqual(1);
    //expect(sut.fedExTax.coveragePolicyTypeId).toEqual(1);
    );


    export const createFedExciseExpenses = (): Array<BackendDto.FedExciseExpense> =>
    return [
    is953D : 1, coveragePolicyTypeId : 1, value : 0,
    is953D : 0, coveragePolicyTypeId : 1, value : 1,
    is953D : 0, coveragePolicyTypeId : 2, value : 4,
    is953D : 1, coveragePolicyTypeId : 2, value : 0
    ];
    ;






    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am writing Jasmine tests in an Angular application and need to verify if I am testing correctly. If not, I would like suggestions in what area I should actually test.



      If you see in the code, harness.fedExciseExpensesInputs is test data created by me. It's like mocking the actual data. The property returns a filtered value if currentSelectedCoveragePolicy is not equal to zero, else it will return _fedExTax which is defined in the declarations.



      Here is the property in the component that I am testing called fedExTax:



      Component code:



      @Input() fedExciseExpensesInputs: Array<BackendDto.FedExciseExpense>;
      @Input() currentSelectedCurrency: string;
      @Input() currentSelectedCoveragePolicy: number;
      @Input() currentSelected953D: number;
      private _fedExTax: BackendDto.FedExciseExpense = value: 0, coveragePolicyTypeId: null, is953D: null ;

      get fedExTax(): BackendDto.FedExciseExpense
      if (this.currentSelectedCoveragePolicy !== 0)
      this.isReadOnly = false;
      return this.fedExciseExpensesInputs.find(x => x.coveragePolicyTypeId === this.currentSelectedCoveragePolicy && x.is953D === this.currentSelected953D);
      else
      this.isReadOnly = true;
      return this._fedExTax;




      Test code:



       beforeEach(() => 
      fixture = TestBed.createComponent(HostFormTestComponent);
      harness = fixture.componentInstance;
      fixture.detectChanges();
      sut = harness.componentUnderTest;
      harness.incrementalExpensesInputs = IncrementalExpenses;
      harness.fedExciseExpensesInputs = fedExciseTaxExpenses;
      fixture.detectChanges();
      );

      it('should set fields correctly when currentSelectedCoveragePolicy is 0', () =>
      sut.fedExTax.coveragePolicyTypeId = 0;
      fixture.detectChanges();
      //expect(sut.fedExTax.coveragePolicyTypeId).toBeNull();
      expect(sut.fedExciseExpensesInputs).toBeNull();
      );

      it('should set fields correctly when currentSelectedCoveragePolicy is 1', () =>
      sut.currentSelectedCoveragePolicy = 1;
      fixture.detectChanges();
      expect(sut.fedExciseExpensesInputs[0].coveragePolicyTypeId).toEqual(1);
      //expect(sut.fedExTax.coveragePolicyTypeId).toEqual(1);
      );


      export const createFedExciseExpenses = (): Array<BackendDto.FedExciseExpense> =>
      return [
      is953D : 1, coveragePolicyTypeId : 1, value : 0,
      is953D : 0, coveragePolicyTypeId : 1, value : 1,
      is953D : 0, coveragePolicyTypeId : 2, value : 4,
      is953D : 1, coveragePolicyTypeId : 2, value : 0
      ];
      ;






      share|improve this question













      I am writing Jasmine tests in an Angular application and need to verify if I am testing correctly. If not, I would like suggestions in what area I should actually test.



      If you see in the code, harness.fedExciseExpensesInputs is test data created by me. It's like mocking the actual data. The property returns a filtered value if currentSelectedCoveragePolicy is not equal to zero, else it will return _fedExTax which is defined in the declarations.



      Here is the property in the component that I am testing called fedExTax:



      Component code:



      @Input() fedExciseExpensesInputs: Array<BackendDto.FedExciseExpense>;
      @Input() currentSelectedCurrency: string;
      @Input() currentSelectedCoveragePolicy: number;
      @Input() currentSelected953D: number;
      private _fedExTax: BackendDto.FedExciseExpense = value: 0, coveragePolicyTypeId: null, is953D: null ;

      get fedExTax(): BackendDto.FedExciseExpense
      if (this.currentSelectedCoveragePolicy !== 0)
      this.isReadOnly = false;
      return this.fedExciseExpensesInputs.find(x => x.coveragePolicyTypeId === this.currentSelectedCoveragePolicy && x.is953D === this.currentSelected953D);
      else
      this.isReadOnly = true;
      return this._fedExTax;




      Test code:



       beforeEach(() => 
      fixture = TestBed.createComponent(HostFormTestComponent);
      harness = fixture.componentInstance;
      fixture.detectChanges();
      sut = harness.componentUnderTest;
      harness.incrementalExpensesInputs = IncrementalExpenses;
      harness.fedExciseExpensesInputs = fedExciseTaxExpenses;
      fixture.detectChanges();
      );

      it('should set fields correctly when currentSelectedCoveragePolicy is 0', () =>
      sut.fedExTax.coveragePolicyTypeId = 0;
      fixture.detectChanges();
      //expect(sut.fedExTax.coveragePolicyTypeId).toBeNull();
      expect(sut.fedExciseExpensesInputs).toBeNull();
      );

      it('should set fields correctly when currentSelectedCoveragePolicy is 1', () =>
      sut.currentSelectedCoveragePolicy = 1;
      fixture.detectChanges();
      expect(sut.fedExciseExpensesInputs[0].coveragePolicyTypeId).toEqual(1);
      //expect(sut.fedExTax.coveragePolicyTypeId).toEqual(1);
      );


      export const createFedExciseExpenses = (): Array<BackendDto.FedExciseExpense> =>
      return [
      is953D : 1, coveragePolicyTypeId : 1, value : 0,
      is953D : 0, coveragePolicyTypeId : 1, value : 1,
      is953D : 0, coveragePolicyTypeId : 2, value : 4,
      is953D : 1, coveragePolicyTypeId : 2, value : 0
      ];
      ;








      share|improve this question












      share|improve this question




      share|improve this question








      edited May 28 at 5:50









      Jamal♦

      30.1k11114225




      30.1k11114225









      asked May 13 at 7:10









      Tom

      1113




      1113

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194297%2fjasmine-tests-for-tax-calculations-in-angular-4%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194297%2fjasmine-tests-for-tax-calculations-in-angular-4%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?