easyFull Stack EngineerTechnology
How would you implement Test-Driven Development (TDD) for a real feature — describe the workflow
Posted 18/04/2026
by Mehedy Hasan Ador
Question Details
At a company adopting TDD:
> "We want to try TDD for our new 'application deadline reminder' feature. Every application has a deadline, and we send an email 24h before. Walk me through the TDD workflow."
> "We want to try TDD for our new 'application deadline reminder' feature. Every application has a deadline, and we send an email 24h before. Walk me through the TDD workflow."
Suggested Solution
TDD Cycle: Red → Green → Refactor
1. 🔴 RED: Write a failing test
2. 🟢 GREEN: Write minimal code to pass
3. 🔵 REFACTOR: Clean up while tests pass
4. Repeat
Feature: Deadline Reminders
Step 1: RED — Test for finding upcoming deadlines
// deadline-reminder.test.ts
describe("getUpcomingDeadlines", () => {
it("returns applications due within 24 hours", () => {
const now = new Date();
const applications = [
{ id: "1", deadline: new Date(now.getTime() + 12 * 3600000) }, // 12h away
{ id: "2", deadline: new Date(now.getTime() + 48 * 3600000) }, // 48h away
{ id: "3", deadline: new Date(now.getTime() - 1 * 3600000) }, // Past
];
const result = getUpcomingDeadlines(applications, now);
expect(result).toHaveLength(1);
expect(result[0].id).toBe("1");
});
});
// Run test → FAILS (getUpcomingDeadlines doesn't exist)
Step 2: GREEN — Minimal implementation
// deadline-reminder.ts
export function getUpcomingDeadlines(applications: App[], now: Date): App[] {
const in24h = new Date(now.getTime() + 24 * 3600000);
return applications.filter(app => app.deadline > now && app.deadline <= in24h);
}
// Run test → PASSES ✅
Step 3: REFACTOR (if needed)
// Clean up variable names, add types
export function getUpcomingDeadlines(apps: Application[], referenceDate: Date): Application[] {
const twentyFourHoursFromNow = new Date(referenceDate.getTime() + 24 * HOUR_MS);
return apps.filter(({ deadline }) =>
deadline > referenceDate && deadline <= twentyFourHoursFromNow
);
}
// Tests still pass ✅
Step 4: Repeat — Add email sending test
it("sends reminder email for each upcoming deadline", async () => {
const apps = [{ id: "1", deadline: in12Hours, userId: "u1", company: "Google" }];
const mockSend = vi.fn().mockResolvedValue(undefined);
await sendDeadlineReminders(apps, mockSend);
expect(mockSend).toHaveBeenCalledTimes(1);
expect(mockSend).toHaveBeenCalledWith(
expect.objectContaining({ subject: expect.stringContaining("Google") })
);
});