Skip to content

test+docs: improve tests and examples about allowNull - #16299

Merged
vkarpov15 merged 6 commits into
masterfrom
vkarpov15/allownull-cleanup
May 28, 2026
Merged

test+docs: improve tests and examples about allowNull#16299
vkarpov15 merged 6 commits into
masterfrom
vkarpov15/allownull-cleanup

Conversation

@vkarpov15

Copy link
Copy Markdown
Collaborator

Summary

Add a quick example and some tests elaborating on how allowNull handles keys that are explicitly set to undefined.

Examples

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves coverage and documentation around how allowNull: false behaves when paths are omitted vs explicitly set to undefined, including behavior in validation, saving, and findOneAndUpdate() with runValidators.

Changes:

  • Expand validation tests to cover {} vs { name: undefined } for allowNull: false.
  • Adjust findOneAndUpdate() tests to demonstrate that $set: { name: undefined } is stripped and does not modify the stored value.
  • Update SchemaType#allowNull JSDoc example to include the {} case and clarify undefined behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/schema.validation.test.js Adds a validation case for an omitted allowNull: false path ({}) to confirm it isn’t implicitly required.
test/model.findOneAndUpdate.test.js Updates the runValidators test to assert behavior when $set contains undefined (no-op after Mongoose strips it).
test/document.test.js Adds a save/insert regression test illustrating how undefined is handled for allowNull: false paths (top-level and nested).
lib/schemaType.js Updates the allowNull API docs example to cover omitted paths and clarify undefined treatment.

Comment thread test/document.test.js Outdated
Comment thread lib/schemaType.js
vkarpov15 and others added 2 commits May 27, 2026 11:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@vkarpov15 vkarpov15 modified the milestones: 9.6.3, 9.7 May 27, 2026

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM

Comment thread test/model.findOneAndUpdate.test.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@vkarpov15
vkarpov15 merged commit e6a51d0 into master May 28, 2026
52 checks passed
@vkarpov15
vkarpov15 deleted the vkarpov15/allownull-cleanup branch May 28, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants