-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cy.request: RequestBody type not aligned with RFC (e.g. boolean) #28789
Comments
@PeterRistMHP That's fun. We'd be open to a pull request to fix the types. |
I'm afraid it's not only a type issue. I've changed the type, but sending the request with
I haven't found the source of this exception yet. |
This is a problem with the @cypress/request-promise library. Indeed the JSON spec allows for boolean and null value literals so you should be able to use this as My idea for a fix would be to
I can open a PR on this 😀 |
…ies (#28835) * fix(types): RequestBody type should be able to accept booleans and null values, which are all valid JSON literals * refactor: boolean literals are valid JSON objects. Null values should also be considered valid when explicitly passed to the request function. * refactor: body is explicitly defined when passed as positional argument or when supplied through the options object * test: JSON literals should be parsed as valid JSON and set json=true * docs: issue reference * fix: boolean and null literal should be send to request promise as strings * docs: fixes #28789 -- added issue reference * test: tests proper conversion of JSON literals to strings. * docs: added isssue reference * docs: fixes #28789 -- changelog entry * refactor: change isValidJsonObj to isValidBody Co-authored-by: Bill Glesias <bglesias@gmail.com> * refactor: change isValidJsonObj to isValidBody Co-authored-by: Bill Glesias <bglesias@gmail.com> * refactor: use lodash utils Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update cli/CHANGELOG.md Co-authored-by: Bill Glesias <bglesias@gmail.com> * docs: moved entry to 13.6.5 * docs: fixed changelog entry * Update CHANGELOG.md --------- Co-authored-by: Bill Glesias <bglesias@gmail.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
I've stumbled on this problem while trying to send only a boolean in a
PUT
request.Currently the type for
RequestBody
is typed astype RequestBody = string | object
[1]. However this doesn't align with the current RFC 8259 for allowed values in JSON [2].[1] https://github.com/cypress-io/cypress/blob/develop/cli/types/cypress.d.ts#L10
[2] https://datatracker.ietf.org/doc/html/rfc8259#section-3
Desired behavior
All values defined in the RFC should be accepted as valid values for the
body
in acy.request()
.Test code to reproduce
cy.request({ method: "PUT", url: ANY_URL_HERE, body: true })
Cypress Version
v13.16.1
Node version
v20.10.0
Operating System
macOS 14.2
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: