Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 14 / Topic 7 of 7

Arranging test data

A growing test file that copy-pastes a slightly-different 6-field literal object into every single test is expensive to maintain - the moment that object grows a new required field, every one of those copies needs the same edit, by hand, everywhere. examples/07_arranging_test_data.jsx's tests use one small factory instead:

// examples/07_arranging_test_data.test.jsx
function makeOrder(overrides = {}) {
  return {
    id: "ZO-1001",
    items: [{ name: "Paneer Tikka", price: 220 }],
    total: 220,
    status: "confirmed",
    ...overrides,
  };
}

Every test below that only spells out the one field it actually cares about - makeOrder({ status: "cancelled" }) for the cancelled-order test, makeOrder() plain for the default-rendering test - and gets a complete, valid order for everything else, for free. This is the same "arrange" idea Testing Library's own examples lean on constantly, just never named as its own step in this course until now - every test above this section already has an implicit arrange/act/assert shape (render(...) to arrange, a click or a query to act, an expect to assert); a factory function is what keeps the "arrange" part from becoming its own maintenance burden as a test file grows.

Done here? The practice set for Part 14 — including the solutions — is on the part page.

Search the guide