Jasmine tests for tax calculations in Angular 4
Clash 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
];
;
unit-testing typescript angular-2+ jasmine
add a comment |Â
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
];
;
unit-testing typescript angular-2+ jasmine
add a comment |Â
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
];
;
unit-testing typescript angular-2+ jasmine
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
];
;
unit-testing typescript angular-2+ jasmine
edited May 28 at 5:50
Jamalâ¦
30.1k11114225
30.1k11114225
asked May 13 at 7:10
Tom
1113
1113
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password