score:2

Accepted answer
`http://localhost:3000/web/reserve${
  label ? optionalSlash + label : ''
  }${
  count ? optionalSlash + count : ''}`

score:0

const webpageCheck = (...args) => {
  const path = [...args].map(arg => `/${arg}`).join('')
  expect(path).not.to.include('undefined')

  const expected = `http://localhost:3000/web/reserve${path}`
  cy.url().should('eq', expected)
}

score:1

const
    web = { label: 'Hello', count: '10' },
    webpageCheck = (label = '', count = '', separator = '/') => 
        ['http://localhost:3000/web/reserve', label, count]
            .filter(Boolean)
            .join(separator);

console.log(webpageCheck());
console.log(webpageCheck(web.label));
console.log(webpageCheck(web.label, web.count));

score:1

const web = {
        label: 'Hello',
        count: '10',
    };
    
const webpageCheck = (label = '', count = '') => {
     //Logic example
     let addressOptionsString=(label!==''? ("/" + label):'') + (count!==''? ("/" + count):'')
      cy.url().should(
         'eq',
         `http://localhost:3000/web/reserve${adressOptionsString}`
        );
    };
    
 webpageCheck()

Related Query

More Query from same tag