Nanciee/cypress-autorecord

Mocks are recorded, but calls are not being stubbed.

Closed this issue · 5 comments

Awesome plugin, unfortunately I ran into an issue with it.

I have an onboarding.spec.js file in which I call autoRecord(__filename);. The mocks from that file get recorded into mocks/onboarding.spec.js successfully:

mocks/onboarding.spec.js:

{
  "Clicks the fill in code button": [
    {
      "url": "https://demo.domain.com/api/auth/request",
      "method": "POST",
      "status": 200,
      "body": {
        "email": "user@fake.com"
      },
      "response": "OK"
    }
  ]
}

Unfortunately, later on when I run the tests, it calls the API normally instead of using the stub.

My cypress.json is empty ({}).

I would really appreciate help in getting this to work.

@TrebuhD
Could you send over what you have in onboarding.spec.js?
Also wanted to confirm that you haven't changed the test name and it is still Clicks the fill in code button?

Hi @Nanciee , thanks for responding. Apologies for the late reply. Here's my onboarding.spec.js:

import autoRecord from "cypress-autorecord";

describe("Onboarding page", function() {
  autoRecord(__filename);

  [...]

  it("Clicks the fill in code button", function() {
    cy.contains("Fill in the code").click();
  });

  [...]
});

By the way, I'm using axios to make the requests. I figured that shouldn't be a factor, since axios uses xmlhttprequest under the hood, but just putting it out there.

I got it to work. The problem was, if the last line in my test was triggering a request asynchronously (like clicking a button), the request itself was being recognised as part of the next test.

Solution: I had to add cy.wait(100) at the end of the problematic tests. Solved! Thanks for your help @Nanciee, amazing plugin.

Glad you found a fix!