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

docs: add { log: false } to StaticResponse #5106

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/api/commands/intercept.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ By passing in a `StaticResponse` as the last argument, you can
requests. See [`StaticResponse` object](#StaticResponse-objects) for the list of
properties.

Additionally, you can pass `{ log: false }` with your `StaticResponse` to disable
command logs for this intercept. See
["Disabling logs for a request"](#Disabling-logs-for-a-request).

See
[Stubbing a response with a `StaticResponse` object](#With-a-StaticResponse-object)
for an example.
Expand Down Expand Up @@ -607,6 +611,17 @@ cy.intercept('POST', 'http://api.company.com/widgets', (req) => {
// real destination
```

### Disabling logs for a request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something worth mentioning in a guide as well? It seems like a very useful pattern, and I wouldn't know to look in the documentation to cy.intercept() to find it. Maybe in the FAQ?


By default, Cypress logs all requests that match any `cy.intercept()`, as well as all `XMLHttpRequest`s and `fetch` requests. You can use `cy.intercept()` to disable these logs by passing `{ log: false }` in the second parameter:

```js
// disable Cypress's default behavior of logging all XMLHttpRequests and fetches
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false })
```

Note: Currently, you can only enable/disable a request's logs when defining the `cy.intercept()`, not inside of an `intercept` callback. See [#26069](https://github.com/cypress-io/cypress/issues/26069).

### Intercepting a response

Inside of a callback passed to `req.continue()`, you can access the destination
Expand Down