Add a script to your package.json to run the tests:
"scripts": {
"test": "jest"
}
# Setup Tests
Create Tests directory
Create a tests directory in your project in the project root, adjacent to your src directory.
Create a Test
Tests are TypeScript files that end in .test.ts.
Here's an example;
import { MaternityCalc } from'../src/maternityCalc';describe('MaternityCalc', () => {constedd=newDate('2024-06-30');constmaternityCalc=newMaternityCalc(edd);test('should calculate LMP date correctly', () => {constexpectedLmpDate=newDate('2023-09-24');expect(maternityCalc.lmpDate.toISOString().split('T')[0]).toBe(expectedLmpDate.toISOString().split('T')[0]); });test('should calculate correct dayOf', () => {// You need to adjust the test depending on the current date.// Assuming today is 2024-06-30 for this test:jest.setSystemTime(newDate('2024-06-30'));expect(maternityCalc.dayOf).toBe(280); });test('should calculate correct weekOf', () => {// Assuming today is 2024-06-30 for this test:jest.setSystemTime(newDate('2024-06-30'));expect(maternityCalc.weekOf).toBe(41); // 280 days is 40 weeks, plus 1 for 1-based index });test('should create instance from LMP date correctly', () => {constlmp=newDate('2023-09-24');constinstance=MaternityCalc.createFromLMP(lmp);constexpectedEdd=newDate('2024-06-30');expect(instance._edd.toISOString().split('T')[0]).toBe(expectedEdd.toISOString().split('T')[0]); });});