-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: mortgage calculator unit tests
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { mortgageCalculator } from "./mortgageCalculator"; | ||
|
||
describe("mortgageCalculator", () => { | ||
it("should calculate an interest only mortgage with the correct payments and pricipal", () => { | ||
const result = mortgageCalculator( | ||
{ | ||
homeValue: 150_000, | ||
deposit: 15_000, | ||
interestRate: 6, | ||
years: 25 | ||
}, | ||
"interestOnly" | ||
); | ||
|
||
expect(result).toMatchObject({ | ||
homeValue: 150000, | ||
deposit: 15000, | ||
interestPayments: { | ||
yearly: 8100, | ||
monthly: 675, | ||
period: 675 | ||
}, | ||
principal: 135000, | ||
years: 25, | ||
interestRate: 6 | ||
}); | ||
}); | ||
|
||
it("should calculate a repayment mortgage with the correct monthly payment and remaining principal rounded to two decimal places", () => { | ||
const result = mortgageCalculator( | ||
{ | ||
homeValue: 150_000, | ||
deposit: 15_000, | ||
interestRate: 6, | ||
years: 25 | ||
}, | ||
"repayment" | ||
); | ||
|
||
expect(result).toMatchObject({ | ||
deposit: 15000, | ||
homeValue: 150000, | ||
interestRate: 6, | ||
monthlyRepayment: 869.81, | ||
principal: 135000, | ||
years: 25 | ||
}); | ||
}); | ||
}); |