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

FixtureId is not working with req.reply #54

Closed
ErichSA opened this issue Jun 22, 2021 · 2 comments · Fixed by #58
Closed

FixtureId is not working with req.reply #54

ErichSA opened this issue Jun 22, 2021 · 2 comments · Fixed by #58

Comments

@ErichSA
Copy link

ErichSA commented Jun 22, 2021

Cypress is not returning the fixture
index.js line 169: req.reply(response.status, newResponse, response.headers);
It's returning the fixture folder instead.
image
Changing it to:

let newResponse = response.response;
            if (response.fixtureId) {
              newResponse = {
                statusCode: response.status,
                fixture: `${fixturesFolderSubDirectory}/${response.fixtureId}.json`
              };
            }
req.reply(newResponse, response.headers);

Everything works.

@ErichSA
Copy link
Author

ErichSA commented Jun 22, 2021

Can I open a PR?
This is the cypress documentation:
image
https://docs.cypress.io/api/commands/intercept#Request-Response-Modification-with-routeHandler

@MasterATM
Copy link

Hello,
I got the same problem as initially described despite using the latest 3.1.2 version.
The signature for res.send is different if we want to reply with either the direct response or a fixture.

If if modify the code to this, then it works:

            req.reply((res) => {
              const newResponse = sortedRoutes[method][url][index];
              if (newResponse.fixtureId) {
                res.send(
                  {
                        fixture: `${fixturesFolderSubDirectory}/${newResponse.fixtureId}.json`,
                        headers: newResponse.headers,
                        statusCode: newResponse.status
                  }
                );  
              } else {
                res.send(
                  newResponse.status,
                  newResponse.response,
                  newResponse.headers,
                );  
              }

Thanks.

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 a pull request may close this issue.

2 participants