PapaParse unparse: testing optional fields that first appear after the initial row
Design the CSV export test around the explicit field contract, not an assumption that the first object represents all rows.
PapaParse unparse: testing optional fields that first appear after the initial row
A field absent from the first object can still belong to the approved export schema. Inferring columns from that object alone may omit later optional information while the initial preview looks correct. Track where a field first appears separately from the decision to publish it. [1, 2, 3]
What the primary source establishes
A report describes unparse deriving headers from the first object's keys and excluding keys introduced only in later rows. Empty cells for absent keys differ from loss of an additional key that appears later. [1]
The handover decision
Create an input whose optional field first appears later. Compare explicitly declared fields with the default export and inspect whether approved fields were lost. Retain declared_field, first_seen_row, and exported_header so a plausible header does not become an implicit schema decision. [1, 3]
A reference defined before the output
The illustrative first row contains a and b; the next contains a, b, and c. If the approved contract includes c, its header status should be present. An absent status fails even though c was not in the first row. The reference inventory is the approved export schema, not every field discovered in raw input. [1, 3]
The scoped Truthound check
Truthound Core 3.3.2 offers ColumnExistsValidator to check for c in the actual reread CSV table. Maintain an approved field inventory rather than automatically publishing every discovered key. After confirming column presence, reconcile the preservation of each row's c value separately. [1, 2, 3]
Limits and alternative choices
Automatically publishing the union of all discovered keys can expose internal fields. Declare the approved fields explicitly and send newly discovered keys through schema-change review. If the approved export schema contains only a and b, excluding c is intentional projection rather than a loss. [1, 3]
Application conditions
Prepare the approved export field inventory and inspect the actual parsed CSV columns, retaining source-row correspondence.
Alternatives
Declare the approved fields explicitly and send newly discovered keys through schema-change review.
Limitations
Automatically publishing the union of all discovered keys can expose internal fields.
Evidence
- Event checked
- Subject checked
- Modified
