Fix: JSONResponse helper to preserve original onResponse behavior (Fixes #5042)#5106
Fix: JSONResponse helper to preserve original onResponse behavior (Fixes #5042)#5106kobenguyent merged 2 commits intocodeceptjs:3.xfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the JSONResponse helper where setting the onResponse handler was overriding any existing custom onResponse handler in the user's configuration. The fix preserves the original onResponse behavior by wrapping it instead of replacing it.
Key changes:
- Preserve existing onResponse handlers by storing and calling the original function
- Maintain backward compatibility while fixing the override issue
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Please add tests if that's possible. Thanks. |
|
@kobenguyent - I’ve added tests under ./test/unit/helper/, but some existing tests are failing, and I can’t push. |
|
@myrepojuly i guess that's fine as we would run tests on GitHub anyway. |
|
@kobenguyent - thank you.. Added the unit tests... |
Motivation/Description of the PR
The current implementation overrides any custom onResponse handler that may have already been set in the user's configuration, causing their logic to be lost.
Suggested Fix:
Preserve the original onResponse handler by wrapping it, rather than replacing it:
onResponseprovided in config does not work #5042Applicable helpers:
Applicable plugins:
Type of change
Checklist:
npm run docs)npm run lint)npm test)