Skip to content

test(query-devtools/utils): cover empty path, array nested path, and primitive cases of 'updateNestedDataByPath'#10672

Merged
sukvvon merged 1 commit into
mainfrom
test/query-devtools-update-nested-data-by-path-coverage
May 9, 2026
Merged

test(query-devtools/utils): cover empty path, array nested path, and primitive cases of 'updateNestedDataByPath'#10672
sukvvon merged 1 commit into
mainfrom
test/query-devtools-update-nested-data-by-path-coverage

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 9, 2026

🎯 Changes

Cover the three remaining branches of the updateNestedDataByPath helper in query-devtools/utils.tsx. The existing suite already exercises the single-step array, object, set, map, and deeply-nested cases; this PR fills in the branches that weren't hit yet.

Cases:

  • empty path — returns the new value as-is when updatePath is empty
  • array nested path — recurses into an element of an array when updatePath.length > 1
  • primitive — returns primitive data unchanged when it is not an Object / Array / Map / Set

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for utility functions, including edge cases for empty paths, nested array updates, and primitive value handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Three new test suites were added to verify updateNestedDataByPath utility behavior: empty path replacement (returns replacement unchanged), nested array element updates (modifies targeted property within array), and primitive input handling (returns original primitive values unchanged).

Changes

Test Coverage for updateNestedDataByPath

Layer / File(s) Summary
Test Cases
packages/query-devtools/src/__tests__/utils.test.ts
Added test coverage for updateNestedDataByPath with three new suites: empty path behavior, nested updates within arrays, and primitive input handling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

🐰 A test suite grows with paths so clear,
Empty, nested, primitives dear,
updateNestedData bends and twists,
No edge case our coverage misses!
The devtools shine ever so bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding test coverage for three specific branches of 'updateNestedDataByPath'.
Description check ✅ Passed The description fully follows the template structure, clearly explains the changes, includes all required checklist items, and correctly marks the release impact as dev-only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-devtools-update-nested-data-by-path-coverage

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 9, 2026

View your CI Pipeline Execution ↗ for commit d778fc0

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 3m 32s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-09 04:59:50 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/query-devtools/src/__tests__/utils.test.ts (1)

146-173: ⚡ Quick win

Add an explicit immutability assertion for the source array/object

The nested-array test checks newData and reference inequality, but it doesn’t verify that oldData content stays unchanged (Line 148-Line 151). Adding that assertion would better guard against accidental in-place mutation regressions.

Suggested test hardening
     describe('array nested path', () => {
       it('should update nested data inside an array correctly', () => {
         const oldData = [
           { id: 1, title: 'first' },
           { id: 2, title: 'second' },
         ]

         const newData = updateNestedDataByPath(
           oldData,
           ['1', 'title'],
           'updated',
         )

         expect(newData).not.toBe(oldData)
+        expect(oldData).toMatchInlineSnapshot(`
+          [
+            {
+              "id": 1,
+              "title": "first",
+            },
+            {
+              "id": 2,
+              "title": "second",
+            },
+          ]
+        `)
         expect(newData).toMatchInlineSnapshot(`
           [
             {
               "id": 1,
               "title": "first",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/query-devtools/src/__tests__/utils.test.ts` around lines 146 - 173,
The test lacks an assertion that the original source (oldData) remains unchanged
after calling updateNestedDataByPath; add an explicit immutability assertion
immediately after calling updateNestedDataByPath to verify oldData’s contents
are intact (for example assert oldData[1].title === 'second' or use
toMatchInlineSnapshot on oldData) so the test checks both reference inequality
(newData !== oldData) and that updateNestedDataByPath did not mutate oldData.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/query-devtools/src/__tests__/utils.test.ts`:
- Around line 146-173: The test lacks an assertion that the original source
(oldData) remains unchanged after calling updateNestedDataByPath; add an
explicit immutability assertion immediately after calling updateNestedDataByPath
to verify oldData’s contents are intact (for example assert oldData[1].title ===
'second' or use toMatchInlineSnapshot on oldData) so the test checks both
reference inequality (newData !== oldData) and that updateNestedDataByPath did
not mutate oldData.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3588a653-d721-4e7f-96f0-81dc09a9b29c

📥 Commits

Reviewing files that changed from the base of the PR and between 64d0b89 and d778fc0.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/utils.test.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10672

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10672

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10672

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10672

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10672

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10672

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10672

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10672

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10672

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10672

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10672

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10672

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10672

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10672

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10672

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10672

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10672

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10672

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10672

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10672

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10672

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10672

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10672

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10672

commit: d778fc0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

size-limit report 📦

Path Size
react full 12.1 KB (0%)
react minimal 9.07 KB (0%)

@sukvvon sukvvon self-assigned this May 9, 2026
@sukvvon sukvvon merged commit 8dd9724 into main May 9, 2026
10 checks passed
@sukvvon sukvvon deleted the test/query-devtools-update-nested-data-by-path-coverage branch May 9, 2026 05:08
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.

1 participant