IK
Interview Knowledge Book
Topics
Practice
Examples
Playground
RU
browser
Deterministic test fixture
Use a fixed clock and fixture data so a test-style assertion is repeatable.
index.js
const now = new Date('2026-06-15T00:00:00Z'); const invoice = { createdAt: '2026-06-13T00:00:00Z', total: 120 }; const ageDays = (now - new Date(invoice.createdAt)) / 86400000; const expected = { overdue: false, ageDays: 2 }; const actual = { overdue: ageDays > 30, ageDays }; console.log('invoice age days', actual.ageDays); console.log('assert', JSON.stringify(actual) === JSON.stringify(expected));
Run
Stop
Reset