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

rename cy.http to cy.intercept #3340

Merged
merged 10 commits into from
Nov 23, 2020
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ alias:
api/assertions/assertions.html: guides/references/assertions.html
api/commands/cypress-blob.html: api/utilities/blob.html
api/commands/api-server.html: api/cypress-api/cypress-server.html
api/commands/route2.html: api/commands/http.html
api/commands/route2.html: api/commands/intercept.html

examples/index.html: examples/examples/recipes.html

Expand Down
14 changes: 7 additions & 7 deletions source/_changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

**Summary:**

Cypress now offers full network stubbing support with the introduction of the {% url "`cy.http()`" http %} command (previously `cy.route2()`). With {% url "`cy.http()`" http %} your tests can intercept, modify and wait on any type of HTTP request originating from your app.
Cypress now offers full network stubbing support with the introduction of the {% url "`cy.intercept()`" intercept %} command (previously `cy.route2()`). With {% url "`cy.intercept()`" intercept %} your tests can intercept, modify and wait on any type of HTTP request originating from your app.

**Breaking Changes:**

**{% fa fa-exclamation-triangle red %} Please read our {% url "Migration Guide" migration-guide %} which explains the changes in more detail and how to change your code to migrate to Cypress 6.0.**

- Cypress now always throws an error when asserting on an element that doesn't exist in the DOM (unless you're asserting that the element should `not.exist`). Assertions such as `not.visible`, `not.contains`, `not.have.class`, etc will now fail when used on non-existent DOM elements. Addresses {% issue 205 %}.
- DOM elements where the CSS style (or ancestors) are `opacity: 0` are no longer considered visible. However these are still considered {% url "actionable" interacting-with-elements %} and {% url "any action commands" interacting-with-elements#Actionability %} used to interact with the element will perform the action. This matches browser's implementation on how they regard elements with `opacity: 0`. Addresses {% issue 4474 %}.
- The type yielded by {% url "`cy.wait(alias)`" wait %} has changed in order to support use of {% url "`cy.http()`" http %}. Addressed in {% issue 9266 %}.
- The type yielded by {% url "`cy.wait(alias)`" wait %} has changed in order to support use of {% url "`cy.intercept()`" intercept %}. Addressed in {% issue 9266 %}.
- The `experimentalNetworkStubbing` option has been removed and made the default behavior. You can safely removed this configuration option. Addressed in {% issue 9185 %}.
- We removed several deprecation errors around APIs that were removed in versions of Cypress prior to 4.0.0. This will not cause any changes for anyone upgrading from a 4.0+ version of Cypress. For a full list of all APIs affected see {% issue 8946 %}.
- We updated our HTTP status codes and reason phrases to match Node.js `http.STATUS_CODES`. If you have code that relies on a reason phrase, then this could affect you. Addressed in {% issue 8969 %}.
Expand All @@ -22,13 +22,13 @@ Cypress now offers full network stubbing support with the introduction of the {%

Deprecations still work as before but will be removed from Cypress in a future release. We encourage you to update your code now to remove uses of deprecations.

- `cy.server()` and `cy.route()` have been deprecated. In a future release, support for `cy.server()` and `cy.route()` will be moved to a plugin. We encourage you to use {% url "`cy.http()`" http %} instead. Addressed in {% issue 9185 %}.
- `experimentalFetchPolyfill` has been deprecated. We encourage you to use {% url "`cy.http()`" http %} to intercept requests using the Fetch API instead.
- `cy.route2()` was renamed to {% url "`cy.http()`" http %}. We encourage you to update usages of `cy.route2()` to use {% url "`cy.http()`" http %}. Addressed in {% issue 9182 %}.
- `cy.server()` and `cy.route()` have been deprecated. In a future release, support for `cy.server()` and `cy.route()` will be moved to a plugin. We encourage you to use {% url "`cy.intercept()`" intercept %} instead. Addressed in {% issue 9185 %}.
- `experimentalFetchPolyfill` has been deprecated. We encourage you to use {% url "`cy.intercept()`" intercept %} to intercept requests using the Fetch API instead.
- `cy.route2()` was renamed to {% url "`cy.intercept()`" intercept %}. We encourage you to update usages of `cy.route2()` to use {% url "`cy.intercept()`" intercept %}. Addressed in {% issue 9182 %}.

**Features:**

- The new {% url "`cy.http()`" http %} command can be used to manage the behavior of HTTP requests at the network layer. Addressed in {% issue 9182 %}.
- The new {% url "`cy.intercept()`" intercept %} command can be used to manage the behavior of HTTP requests at the network layer. Addressed in {% issue 9182 %}.
- We now pass `—disable-dev-shm-usage` to the Chrome browser flags by default. This will write shared memory files into `/tmp` instead of `/dev/shm`. If you're passing this flag in your `plugins` file, you can now remove this code. Addresses {% issue 5336 %}.
- A warning is now displayed when passing invalid configuration keys through the CLI. Addresses {% issue 428 %}.
- The `cypress version` command now also displays the current Electron and bundled Node versions. Addresses {% issue 9180 %}.
Expand All @@ -43,7 +43,7 @@ Deprecations still work as before but will be removed from Cypress in a future r
**Documentation Changes:**

- Our {% url "Migration Guide" migration-guide %} has a new section for 6.0 migration.
- Many of our docs examples have been updated to use {% url "`cy.http()`" http %} in place of `cy.route()` including our {% url "Network Requests" network-requests %} doc.
- Many of our docs examples have been updated to use {% url "`cy.intercept()`" intercept %} in place of `cy.route()` including our {% url "Network Requests" network-requests %} doc.

**Misc:**

Expand Down
2 changes: 1 addition & 1 deletion source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ api:
go: go.html
hash: hash.html
hover: hover.html
http: http.html
intercept: intercept.html
invoke: invoke.html
its: its.html
last: last.html
Expand Down
2 changes: 1 addition & 1 deletion source/_partial/network_stubbing_warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

**To support requests using the Fetch API you can use one of the solutions below:**

- Use [`cy.http()`](/api/commands/http.html) which supports requests using the Fetch API and other types of network requests like page loads. See [`cy.http()`](/api/commands/http.html).
- Use [`cy.intercept()`](/api/commands/intercept.html) which supports requests using the Fetch API and other types of network requests like page loads. See [`cy.intercept()`](/api/commands/intercept.html).
- Polyfill `window.fetch` to spy on and stub requests using `cy.route()` and `cy.server()` by enabling [`experimentalFetchPolyfill`](https://on.cypress.io/experimental). See {% issue 95 %} for more details and temporary workarounds.
{% endnote %}
2 changes: 1 addition & 1 deletion source/_partial/xhr_stubbing_deprecated.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% note warning %}
⚠️ **`cy.server()` and `cy.route()` are deprecated in Cypress 6.0.0**. In a future release, support for `cy.server()` and `cy.route()` will be moved to a plugin. Consider using [`cy.http()`](/api/commands/http.html) instead.
⚠️ **`cy.server()` and `cy.route()` are deprecated in Cypress 6.0.0**. In a future release, support for `cy.server()` and `cy.route()` will be moved to a plugin. Consider using [`cy.intercept()`](/api/commands/intercept.html) instead.
{% endnote %}
14 changes: 7 additions & 7 deletions source/api/commands/as.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Assign an alias for later use. Reference the alias later within a {% url `cy.get

```javascript
cy.get('.main-nav').find('li').first().as('firstNav') // Alias element as @firstNav
cy.http('PUT', 'users').as('putUser') // Alias route as @putUser
cy.intercept('PUT', 'users').as('putUser') // Alias route as @putUser
cy.stub(api, 'onUnauth').as('unauth') // Alias stub as @unauth
cy.spy(win, 'fetch').as('winFetch') // Alias spy as @winFetch
```
Expand Down Expand Up @@ -59,7 +59,7 @@ it('disables on click', () => {
Aliasing a route and then using {% url `cy.wait()` wait %} to wait for the aliased route.

```javascript
cy.http('PUT', 'users', { fixture: 'user' }).as('putUser')
cy.intercept('PUT', 'users', { fixture: 'user' }).as('putUser')
cy.get('form').submit()
cy.wait('@putUser')
.its('url').should('contain', 'users')
Expand Down Expand Up @@ -150,11 +150,11 @@ describe('A fixture', () => {
***Alias several routes***

```javascript
cy.http(/company/).as('companyGet')
cy.http(/roles/).as('rolesGet')
cy.http(/teams/).as('teamsGet')
cy.http(/users\/\d+/).as('userGet')
cy.http('PUT', /^\/users\/\d+/).as('userPut')
cy.intercept(/company/).as('companyGet')
cy.intercept(/roles/).as('rolesGet')
cy.intercept(/teams/).as('teamsGet')
cy.intercept(/users\/\d+/).as('userGet')
cy.intercept('PUT', /^\/users\/\d+/).as('userPut')
```

Aliases of routes display in the routes instrument panel:
Expand Down
2 changes: 1 addition & 1 deletion source/api/commands/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cy.exec('npm run my-script').its('stdout').should('contain', 'Done running the s
### Write to a file to create a fixture from response body

```javascript
cy.http('POST', '/comments').as('postComment')
cy.intercept('POST', '/comments').as('postComment')
cy.get('.add-comment').click()
cy.wait('@postComment').then(({ response }) => {
cy.exec(`echo ${JSON.stringify(response.body)} >cypress/fixtures/comment.json`)
Expand Down
10 changes: 5 additions & 5 deletions source/api/commands/fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ cy.fixture('audio/sound.mp3', 'base64').then((mp3) => {

```javascript
cy.fixture('users').then((json) => {
cy.http('GET', '/users/**', json)
cy.intercept('GET', '/users/**', json)
})
```

Expand All @@ -154,7 +154,7 @@ You can modify fixture data directly before passing it along to a route.
```javascript
cy.fixture('user').then((user) => {
user.firstName = 'Jane'
cy.http('GET', '/users/1', user).as('getUser')
cy.intercept('GET', '/users/1', user).as('getUser')
})

cy.visit('/users')
Expand All @@ -169,10 +169,10 @@ cy.wait('@getUser').then(({ request }) => {

### Using the `fixture` `StaticResponse` property

Fixtures can also be referenced directly without using the `.fixture()` command by using the special property `fixture` on the {% url `cy.http()` http %} `StaticResponse` object.
Fixtures can also be referenced directly without using the `.fixture()` command by using the special property `fixture` on the {% url `cy.intercept()` intercept %} `StaticResponse` object.

```javascript
cy.http('GET', '/users/**', { fixture: 'users' })
cy.intercept('GET', '/users/**', { fixture: 'users' })
```

## Validation
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('User page', () => {

# See also

- {% url `cy.http()` http %}
- {% url `cy.intercept()` intercept %}
- {% url `.then()` then %}
- {% url 'Recipe: Bootstrapping App Test Data' recipes#Server-Communication %}
- {% url 'Fixtures' https://github.com/cypress-io/testing-workshop-cypress#fixtures %} section of the Cypress Testing Workshop
Loading