Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a function for a cy.route response #152

Closed
paulfalgout opened this issue Jun 3, 2016 · 3 comments
Closed

Accept a function for a cy.route response #152

paulfalgout opened this issue Jun 3, 2016 · 3 comments
Assignees
Labels
type: feature New feature that does not currently exist
Milestone

Comments

@paulfalgout
Copy link
Contributor

paulfalgout commented Jun 3, 2016

Passing response data to a cy.route should accept a function, and optionally await promises returned from the function
Doing so enables easier access to properties such as aliased fixtures.

Now:

cy.server()
  .fixture('foos').as('fxFoos')
  .then(function() {
    cy.route('GET', /foo\/\d/, {
      data: {
        foo: _.first(this.fxFoos)
      }
    });
  });
cy.server()
   .fixture('foos').as('fxFoos')
   .route('GET', /foo\/\d/, function() {
     return {
       data: {
         foo: _.first(this.fxFoos)
        }
       };
     });
   });

Particularly useful for:

function fooRoute(resultCount) {
  _.initial(this.fxFoos, resultCount);
}

cy.server()
   .fixture('foos').as('fxFoos')
   .route('GET', /foo\/\d/, _.partial(fooRoute, 4));
@brian-mann brian-mann added this to the 0.16.2 milestone Jun 9, 2016
@brian-mann
Copy link
Member

This is done and will likely release this weekend.

You'll be able to set response as a function which returns a Promise (which will be awaited) or a value.

Additionally we've updated the cy.route signature to take also just take a function which can also return a promise or an object with the typical routing signature.

@brian-mann brian-mann self-assigned this Jun 9, 2016
@paulfalgout
Copy link
Contributor Author

Fantastic

@jennifer-shehane jennifer-shehane added the type: feature New feature that does not currently exist label Jun 10, 2016
@brian-mann
Copy link
Member

Fixed in 0.16.2.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Dec 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

3 participants