Skip to content

Commit

Permalink
test: mortgage calculator unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JDIZM committed Jan 29, 2024
1 parent 22bb368 commit 852a76e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions calc/mortgageCalculator.test.ts
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
});
});
});

0 comments on commit 852a76e

Please sign in to comment.