Skip to content
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

Are the types in net-stubbing correct? #8694

Closed
bahmutov opened this issue Sep 29, 2020 · 3 comments · Fixed by #8698
Closed

Are the types in net-stubbing correct? #8694

bahmutov opened this issue Sep 29, 2020 · 3 comments · Fixed by #8698

Comments

@bahmutov
Copy link
Contributor

Cypress v5.3.0

Trying to write a test that shows how to modify the response from the server

cy.route2('styles.css', (req) => {
  req.reply((res) => {
    res.send(`${res.body}
      li {
        border: 1px solid pink;
      }
    `)
  })
})

Looking at IntelliSense suggested here

image

Ok, no JSDoc, fine, let's look at d.ts

image

So we have reply(interceptor) I guess, since we want to add to the response from the server

export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse, send?: () => void) => void | Promise<void>

Ok, so res and optional send...

req.reply((res, send) => {
  console.log(res)
  console.log(send)

image

Ohhh, res.send is a function, there is no second parameter

@flotwig
Copy link
Contributor

flotwig commented Sep 29, 2020

yeah, send was from an earlier version of the API design, it is always going to be undefined and should be removed:

export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse, send?: () => void) => void | Promise<void>

and these could use some tsdocs:

export interface IncomingHttpRequest extends IncomingRequest {
destroy(): void
reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
reply(body: string | object, headers?: { [key: string]: string }): void
reply(status: number, body?: string | object, headers?: { [key: string]: string }): void
redirect(location: string, statusCode: number): void
}

does that cover it?

@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: work in progress There is an open PR for this issue [WIP] labels Sep 29, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 30, 2020

The code for this is done in cypress-io/cypress#8698, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels Sep 30, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Oct 14, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants