1

Could someone please help me with passing fixture alias to intercept method in Cypress v 9.0. I remember using the following syntax in Cypress ~4 with route method as cy.route("GET", "**/users/*", "@users") where @users is a fixture defined as cy.fixture('users.json').as('users')

Since the cy.route is deprecated and we switched to using cy.intercept, I cannot seem to find the right syntax for passing fixture alias to the intercept method. I would like to know if the following syntax is possible cy.intercept("GET", "**/users/*", "@users")

Any help is kindly appreciated. Thanks

Fody
  • 23,754
  • 3
  • 20
  • 37

1 Answers1

1

I don't think there's a configuration to use an aliased fixture with intercept.

You can however, use the fixture name explicitly

cy.intercept("GET", "**/users/*", {fixture:'users.json'})   // pattern for fixture use

Given the fixture is now named in the staticResponse object, you may be able to use the alias there (but I don't see it documented)

cy.intercept("GET", "**/users/*", {fixture:'@users'})     // may not work

If you have a specific need to use an aliased value, this pattern is equivalent

cy.get('@alias').then(data => {
  cy.intercept("GET", "**/users/*", {body:data})     // set data staticResponse body
})
Fody
  • 23,754
  • 3
  • 20
  • 37
  • Thanks @Fody for your suggestions. The second option did not work as you mentioned. I am planning to use the option 1 from your suggestion. – shashank hr Apr 13 '22 at 19:15