question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating route alias using post processed fixture data (Blob) is not returning that data

See original GitHub issue

Current behavior:

My Angular 5 app makes an HTTP GET request to a remote server which returns an image as a Blob. My existing Cypress specs using the remote server correctly verify the response data is received.

I’d like to stub out the call to the remote server and wrote this spec that loads a JPEG file from disk using a fixture (which returns a dataURI) and then I convert that to a Blob and supply it to cy.route (using the same route minimatch expression that is matched in my non-stubbed request).

in the cypress command log the XHR Stub is being hit and it is returning a Blob of size 2 of type application/json instead of my actual Blob. The cy.wait for the alias also prints Blob size2 application/json to the console.

Here’s my spec:

// spec
describe('Test using fixture to supply image as a Blob', function () {
  before(() => {
    cy.server();
    cy.fixture('images/map.jpeg').then(dataURI => {
      console.log(dataURI);
       return Cypress.Blob.base64StringToBlob(dataURI, "image/jpeg").then((blob) => {
        console.log(blob);
        return cy.route('https://images.mydomain.com/**', blob).as('imageXHR');
      })
    });
  })
  it('test that causes app to call '@imageXHR'), function() {
    ...
  })
});

The console.log statements print what you’d expect - the first is a long data URI and the second is a Blob {size: 41191, type: "image/jpeg"}.

screen shot 2018-06-14 at 9 03 38 pm

I’m not sure what syntax I have wrong or if there is a bug.

Desired behavior:

The post processed fixture data is supplied to the XHR request.

Steps to reproduce:

I’m happy to work on a reproduction if it would help!

Versions

Cypress 3.0.1, OSX

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Airatikicommented, Oct 19, 2020

On 5.3.0 I have the same identical issue of @peterpeterparker. But I rewrite to

return cy.route({
            url,
            method: 'GET',
            response: 'fx:image.png,binary', // where image.png my file in fixtures folder
            headers: {
                'content-type': 'application/octet-stream',
            },
        })

and now it’s working

2reactions
matt328commented, Nov 9, 2018

I have the exact same problem, Cypress@3.1.1, no matter what I try, nothing other than using 'fx:data.json' as the last arg to cy.route() works.

Especially frustrating is this snippet logs my data, but the route always returns no response:

cy.fixture('data.json').as('data');
cy.get('@data').then(d => {
   // Logs data to the console
   console.log({ d });
   cy.route('GET', '/some/url/**', d);
});

Edit:

There seems to be some asynchronous race condition happening, I only have issues if my json data set is rather large. I pared it down to only a few items in an array, and it works normally.

Is there a method or something to make sure it waits until the json data is loaded?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress cy.intercept Problems - Gleb Bahmutov
The POST /todos network call the application has made matches two intercepts, but the Command Log only prints the first intercept's alias. In ......
Read more >
python - "no such table" exception - Stack Overflow
I had a custom user model with ForeignKey to another model. And I set defaults to first object in the DB. It worked...
Read more >
intercept - Cypress Documentation
Waiting on an aliased cy.intercept() route using cy.wait() will yield an object that contains information about the matching request/response cycle.
Read more >
Mocking HTTP Calls in Cypress End-to-End Tests
Don't let unreliable test data keep your new features from making it to ... When using an alias with routes in Cypress, it's...
Read more >
Error creating alias for deprecated data frame notifications index
Filter-based aliases to limit access to data · Combining routing with aliases · Transitioning to new indices · Creating sliding windows into distinct...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found