mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-21 14:40:05 -05:00
feat: add decode option to cy.url (#17930)
This commit is contained in:
Vendored
+13
-1
@@ -2060,7 +2060,7 @@ declare namespace Cypress {
|
||||
* @alias cy.location('href')
|
||||
* @see https://on.cypress.io/url
|
||||
*/
|
||||
url(options?: Partial<Loggable & Timeoutable>): Chainable<string>
|
||||
url(options?: Partial<UrlOptions>): Chainable<string>
|
||||
|
||||
/**
|
||||
* Control the size and orientation of the screen for your application.
|
||||
@@ -3173,6 +3173,18 @@ declare namespace Cypress {
|
||||
eventConstructor: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Options to change the default behavior of .url()
|
||||
*/
|
||||
interface UrlOptions extends Loggable, Timeoutable {
|
||||
/**
|
||||
* Whether the url is decoded
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
decode: boolean
|
||||
}
|
||||
|
||||
/** Options to change the default behavior of .writeFile */
|
||||
interface WriteFileOptions extends Loggable {
|
||||
flag: string
|
||||
|
||||
@@ -483,6 +483,11 @@ namespace CypressLocationTests {
|
||||
cy.location('pathname') // $ExpectType Chainable<string>
|
||||
}
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/17399
|
||||
namespace CypressUrlTests {
|
||||
cy.url({decode: true}).should('contain', '사랑')
|
||||
}
|
||||
|
||||
namespace CypressBrowserTests {
|
||||
Cypress.isBrowser('chrome')// $ExpectType boolean
|
||||
Cypress.isBrowser('firefox')// $ExpectType boolean
|
||||
|
||||
@@ -30,6 +30,15 @@ describe('src/cy/commands/location', () => {
|
||||
cy.url().should('include', '/baz.html')
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/17399
|
||||
it('url decode option', () => {
|
||||
// encodeURI() is used below because we cannot visit the site without it.
|
||||
// For the curious, 사랑 means "love" in Korean.
|
||||
cy.visit(encodeURI('/custom-headers?x=사랑'))
|
||||
|
||||
cy.url({ decode: true }).should('contain', '사랑')
|
||||
})
|
||||
|
||||
describe('assertion verification', () => {
|
||||
beforeEach(function () {
|
||||
cy.on('log:added', (attrs, log) => {
|
||||
|
||||
@@ -8,7 +8,10 @@ module.exports = (Commands, Cypress, cy) => {
|
||||
url (options = {}) {
|
||||
const userOptions = options
|
||||
|
||||
options = _.defaults({}, userOptions, { log: true })
|
||||
options = _.defaults({}, userOptions, {
|
||||
log: true,
|
||||
decode: false,
|
||||
})
|
||||
|
||||
if (options.log !== false) {
|
||||
options._log = Cypress.log({
|
||||
@@ -23,6 +26,10 @@ module.exports = (Commands, Cypress, cy) => {
|
||||
|
||||
const resolveHref = () => {
|
||||
return Promise.try(getHref).then((href) => {
|
||||
if (options.decode) {
|
||||
href = decodeURI(href)
|
||||
}
|
||||
|
||||
return cy.verifyUpcomingAssertions(href, options, {
|
||||
onRetry: resolveHref,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user