Skip to content

Fix "does not have field" assertion to accept undefined#3922

Merged
MintsInc merged 1 commit intomasterfrom
ulysse.mavrocordatos/fix-does-not-have-field-assertion
Apr 13, 2026
Merged

Fix "does not have field" assertion to accept undefined#3922
MintsInc merged 1 commit intomasterfrom
ulysse.mavrocordatos/fix-does-not-have-field-assertion

Conversation

@MintsInc
Copy link
Copy Markdown
Member

Summary

  • ObjectSerializer.deserialize() always assigns instance[attr] = undefined for optional fields absent from the JSON response, so the property key exists on the object even when the field was not present in JSON
  • Chai's .not.have.property() uses hasOwnProperty(), which returns true for undefined-valued keys, causing the "does not have field" step to fail for any optional model field that is absent from the API response
  • Fix: assert .to.be.undefined on the value instead of checking key non-existence — semantically identical for JSON deserialization, but tolerates the way ObjectSerializer initialises optional fields

Test plan

  • Ran full test suite (./run-tests.sh) — 1418 scenarios passed, 0 failed
  • 17 unit tests passed across 4 suites

🤖 Generated with Claude Code

ObjectSerializer.deserialize() always assigns `instance[attr] = undefined`
for optional fields absent from the JSON response, so the property key
exists on the object even when the field was not present. Chai's
`.not.have.property()` uses hasOwnProperty() which returns true for
undefined-valued keys, causing the assertion to fail.

Treat a property value of `undefined` as equivalent to "field not present"
by asserting the value `.to.be.undefined` instead of checking key existence.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@MintsInc MintsInc marked this pull request as ready for review April 13, 2026 14:31
@MintsInc MintsInc requested review from a team as code owners April 13, 2026 14:31
@MintsInc MintsInc merged commit f569eb4 into master Apr 13, 2026
18 of 19 checks passed
@MintsInc MintsInc deleted the ulysse.mavrocordatos/fix-does-not-have-field-assertion branch April 13, 2026 14:37
github-actions Bot pushed a commit that referenced this pull request Apr 13, 2026
ObjectSerializer.deserialize() always assigns `instance[attr] = undefined`
for optional fields absent from the JSON response, so the property key
exists on the object even when the field was not present. Chai's
`.not.have.property()` uses hasOwnProperty() which returns true for
undefined-valued keys, causing the assertion to fail.

Treat a property value of `undefined` as equivalent to "field not present"
by asserting the value `.to.be.undefined` instead of checking key existence.

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> f569eb4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants