Skip to content

Commit

Permalink
fix: Alias name for req.alias containing a dot fail to intercept (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh authored and pashidlos committed Jan 30, 2021
1 parent 90f31d3 commit e35d38f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/driver/cypress/integration/commands/net_stubbing_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,23 @@ describe('network stubbing', { retries: 2 }, function () {

cy.wait('@netAlias').its('response.body').should('equal', 'my value')
})

// https://github.com/cypress-io/cypress/issues/14444
it('can use dot in request alias', () => {
cy.intercept('/users', (req) => {
req.alias = 'get.url'
req.reply('foo')
})

cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()

xhr.open('GET', '/users')
xhr.send()
})

cy.wait('@get.url')
})
})
})
})
11 changes: 8 additions & 3 deletions packages/driver/src/cy/commands/waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ module.exports = (Commands, Cypress, cy, state) => {
_.keys(cy.state('aliases')).includes(str.slice(1))) {
specifier = null
} else {
// potentially request, response or index
// potentially request, response
const allParts = _.split(str, '.')
const last = _.last(allParts)

str = _.join(_.dropRight(allParts, 1), '.')
specifier = _.last(allParts)
if (last === 'request' || last === 'response') {
str = _.join(_.dropRight(allParts, 1), '.')
specifier = _.last(allParts)
} else {
specifier = null
}
}

let aliasObj
Expand Down

0 comments on commit e35d38f

Please sign in to comment.