Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 20, 2025

Fixed the issue with I.seeResponseContainsJson() not working correctly in version 3.7.3. The problem was in the _assertContains method when dealing with arrays.

Root Cause:

  • The _assertContains method was treating arrays as objects and doing index-by-index comparison instead of checking if each expected array element had a corresponding match in the actual array
  • This caused it to only check the first element in arrays rather than searching through all elements

Solution:

  • Modified the _assertContains method to properly handle array matching by detecting when expected values are arrays and implementing proper element-by-element matching logic
  • When the expected value is an array, the method now searches through all elements in the actual array to find matches for each expected element
  • Improved error messages to be more descriptive when matches are not found

Changes Made:

  • Enhanced _assertContains method in lib/helper/JSONResponse.js to handle arrays correctly
  • Updated test expectations in test/helper/JSONResponse_test.js to match new error messages
  • Fixed unrelated test issue with callback test using wrong parameter (assert vs expect)
  • Validated fix with comprehensive tests covering various scenarios
  • Ensured all existing tests still pass

Validation:

  • All unit tests pass (344/344)
  • JSONResponse-specific tests pass (16/16)
  • Created comprehensive test scenarios to verify the fix works for:
    • Array properties within objects (finding elements by position)
    • Response data that is itself an array
    • Multiple element matching
    • Proper failure cases with clear error messages

The fix now correctly searches through all array elements for matches instead of stopping at the first element, restoring the behavior that worked in version 3.6.5.

Fixes #4993.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
@Copilot Copilot AI requested a review from kobenguyent August 20, 2025 13:27
@kobenguyent kobenguyent marked this pull request as ready for review August 20, 2025 13:45
@kobenguyent kobenguyent merged commit 93ab75d into 3.x Aug 20, 2025
11 of 12 checks passed
@kobenguyent kobenguyent deleted the copilot/fix-4993 branch August 20, 2025 13:45
@kobenguyent kobenguyent mentioned this pull request Sep 22, 2025
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.

3.7.3 I.seeResponseContainsJson not working
2 participants