Mock data is deliberately fabricated data supplied by a unit test instead of data from a real application or external source. It makes component behavior predictable while avoiding an actual HTTP call. section 8.3.3
Use mock data to:
- Represent realistic domain records, such as projects or time-off requests, with only the fields needed by the test. section 8.4.1 section 8.3.3
- Return predictable values from a mocked service, commonly wrapped in an Observable, so the component can consume them as though an HTTP request occurred. section 8.3.3
- Exercise additional scenarios by expanding the dataset or changing the mock implementation, including filtering and error cases. section 8.4.1 section 8.3.3
Mocking project data
Define two Project records, then provide them through a mocked ProjectService. A getProject method finds the requested record and returns it with of(...). Render the component with projectId 1 to assert “Project 1”; change the input to 2, detect changes, and assert “Project 2.” section 8.3.3
const timeOffRequests: TimeOffRequest[] = [
{
id: 1,
employeeId: 101,
startDate: '2023-11-01',
endDate: '2023-11-03',
type: 'Vacation',
status: 'Approved',
comment: 'Going on a short vacation'
},
{
id: 2,
employeeId: 102,
startDate: '2023-11-05',
endDate: '2023-11-07',
type: 'Sick Leave',
status: 'Pending'
},
];
Inspect a concrete TimeOffRequest array containing dates, leave types, statuses, and an optional comment. section 8.4.1
