Skip to content

Commit 65ad6c7

Browse files
committed
Some fixes for intercept tests.
1 parent cfd9c52 commit 65ad6c7

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

examples/blogs__vue-vuex-rest/cypress/e2e/api-spec.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Misc tests', () => {
7676
// from a fixture file
7777
it('loads todos from fixture file', () => {
7878
// loads response from "cypress/fixtures/todos.json"
79-
cy.intercept('/todos', 'fixture:todos')
79+
cy.intercept('/todos', { fixture: 'todos' })
8080
cy.visit('/')
8181
getTodoItems()
8282
.should('have.length', 2)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"todos": []
3-
}
3+
}

examples/logging-in__xhr-web-forms/cypress/e2e/logging-in-xhr-web-form-spec.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('Logging In - XHR Web Form', function () {
7272
'POST',
7373
'/login',
7474
{
75-
status: 503,
75+
statusCode: 503,
7676
response: {},
7777
}
7878
)
@@ -86,7 +86,7 @@ describe('Logging In - XHR Web Form', function () {
8686
// we can even test that the correct request
8787
// body was sent in this XHR
8888
cy.wait('@postLogin')
89-
.its('requestBody')
89+
.its('request.body')
9090
.should('deep.eq', {
9191
username: 'jane.lae',
9292
password: 'password123',

examples/server-communication__xhr-assertions/cypress/e2e/clock-control.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ describe('clock', () => {
1414
// force the application to pass 1 second really quickly
1515
// https://on.cypress.io/tick
1616
cy.tick(1001)
17-
cy.wait('@post').should('have.property', 'status', 201)
17+
cy.wait('@post').its('response').should('have.property', 'statusCode', 201)
1818
})
1919
})

examples/server-communication__xhr-assertions/cypress/e2e/multiple-requests.cy.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ describe('waits', () => {
1818
cy.get('@post.all').should('have.length', 2)
1919
.then((xhrs) => {
2020
// xhrs is an array of network call objects
21-
expect(xhrs[0], 'first request status').to.have.property('status', 201)
22-
expect(xhrs[1], 'second request status').to.have.property('status', 201)
21+
expect(xhrs[0].response, 'first request status').to.have.property('statusCode', 201)
22+
expect(xhrs[1].response, 'second request status').to.have.property('statusCode', 201)
2323
})
2424

2525
// and we can make assertions about each separate call
2626
// by retrieving it like this (index starts with 1)
2727
// cy.get('<alias>.<index>')
2828
cy.get('@post.1').should((xhr1) => {
29-
expect(xhr1, 'first request').to.have.property('status', 201)
29+
expect(xhr1.response, 'first request').to.have.property('statusCode', 201)
3030
})
3131

3232
// we cannot guarantee the order of XHR requests - they really depend on the
3333
// server response speed. Sometimes a later request finishes first.
3434
// all we can say that each request should receive a response with
3535
// id equal to 101 or 102
36-
cy.get('@post.1').its('response.body.id').should('be.oneOf', [101, 102])
37-
cy.get('@post.2').its('response.body.id').should('be.oneOf', [101, 102])
36+
cy.get('@post.1').its('response').its('body.id').should('be.oneOf', [101, 102])
37+
cy.get('@post.2').its('response').its('body.id').should('be.oneOf', [101, 102])
3838
})
3939
})

examples/server-communication__xhr-assertions/cypress/e2e/spec.cy.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,21 @@ describe('XHR', { retries: 3 }, () => {
4242
// see https://on.cypress.io/get
4343

4444
// tip: log the request object to see everything it has in the console
45-
cy.get('@post').then(console.log)
45+
cy.wait('@post').then(console.log)
4646

4747
// you can retrieve the XHR multiple times - returns the same object
4848
// confirm the request status
49-
cy.get('@post').should('have.property', 'status', 201)
49+
cy.get('@post').its('response').should('have.property', 'statusCode', 201)
5050

5151
// we cannot chain any more assertions to the above request object
5252
// because the "have.property" assertion yields the property's value
5353
// so let's just grab the request object again and run multiple assertions
5454
cy.get('@post').should((req) => {
55-
expect(req.method).to.equal('POST')
56-
expect(req.url).to.match(/\/posts$/)
55+
console.log('post req', req)
56+
expect(req.request.method).to.equal('POST')
57+
expect(req.request.url).to.match(/\/posts$/)
5758
// it is good practice to add message to the assertion
58-
expect(req, 'has duration in ms').to.have.property('duration').and.be.a('number')
59+
expect(req, 'has a request id').to.have.property('browserRequestId').and.be.a('string')
5960
})
6061

6162
// let's confirm the request sent to the server
@@ -66,7 +67,7 @@ describe('XHR', { retries: 3 }, () => {
6667
})
6768

6869
// alternative: use "requestBody" alias to "request.body" property access
69-
cy.get('@post').its('requestBody')
70+
cy.get('@post').its('request.body')
7071
.should('have.property', 'title', 'example post')
7172

7273
// get the same request object again and confirm the response
@@ -110,8 +111,8 @@ describe('XHR', { retries: 3 }, () => {
110111
//
111112
// https://on.cypress.io/wait
112113
cy.wait('@post').should((xhr) => {
113-
expect(xhr.status, 'successful POST').to.equal(201)
114-
expect(xhr.url, 'post url').to.match(/\/posts$/)
114+
expect(xhr.response.statusCode, 'successful POST').to.equal(201)
115+
expect(xhr.request.url, 'post url').to.match(/\/posts$/)
115116
// assert any other XHR properties
116117
})
117118

examples/stubbing-spying__window-fetch/cypress/e2e/stub-fetch-spec.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('stubbing', function () {
122122
cy.intercept(
123123
'/favorite-fruits',
124124
{
125-
status: 500,
125+
statusCode: 500,
126126
body: '',
127127
delay: 2000,
128128
headers: {

examples/testing-dom__select2/cypress/e2e/spec.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ describe('select2', () => {
183183
// cy.intercept(
184184
// 'https://jsonplaceholder.cypress.io/users?_type=query',
185185
// {
186-
// body: 'fixture:query.json',
186+
// fixture: 'query.json',
187187
// delay: 1000,
188188
// }
189189
// ).as('query')
190190

191191
// cy.intercept(
192192
// 'https://jsonplaceholder.cypress.io/users?term=clem&_type=query&q=clem',
193193
// {
194-
// response: 'fixture:clem.json',
194+
// fixture: 'clem.json',
195195
// delay: 1000,
196196
// }
197197
// ).as('user_search')

0 commit comments

Comments
 (0)