Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 3c2d533

Browse files
committed
add example with dynamic alias
1 parent cf80542 commit 3c2d533

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

cypress/integration/05-xhr/answer-intercept-spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ describe('intercept', () => {
6060
})
6161
})
6262

63+
context.only('dynamic alias', () => {
64+
it('sets the alias after inspecting the request', () => {
65+
cy.intercept('*', (req) => {
66+
if (req.method === 'GET' && req.url.endsWith('/todos')) {
67+
req.alias = 'todos'
68+
}
69+
})
70+
71+
cy.visit('/')
72+
cy.wait('@todos')
73+
})
74+
75+
it.only('creates random alias', () => {
76+
let alias = ''
77+
cy.intercept('GET', '/todos', (req) => {
78+
alias = 'get-todos-' + Cypress._.random(1e6)
79+
req.alias = alias
80+
})
81+
82+
cy.visit('/?delay=2400')
83+
84+
// first, wait for the alias string to become define
85+
cy.wrap('the alias string')
86+
.should(() => {
87+
expect(alias, 'alias string').to.not.be.empty
88+
})
89+
.then(() => {
90+
cy.wait(`@${alias}`)
91+
})
92+
})
93+
})
94+
6395
context('cached data', () => {
6496
// this test might pass or not when the DevTools is open
6597
// depending on the Network "Disable cache" setting

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)