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

Unable to write multiple request intercepts to pact file #44

Open
kand opened this issue Apr 10, 2024 · 3 comments
Open

Unable to write multiple request intercepts to pact file #44

kand opened this issue Apr 10, 2024 · 3 comments

Comments

@kand
Copy link

kand commented Apr 10, 2024

Hello! I have a test that's something like this:

describe('test some UI', () => {
  before(() => cy.setupPact('consumer-ui', 'provider-api');

  it('User is able to do a process that causes two requests I want to record', () => {
    cy.intercept('POST', '/api/thing-one').as('thing-one');
    cy.intercept('POST', '/api/thing-two').as('thing-two');

    // ... interact with UI

    cy.usePactWait('thing-one').then((xhr) => {
      expect(xhr.response.statusCode).to.eq(200);

      // ... UI is in a new state, interact with it again to get the second request
      cy.usePactWait('thing-two').then((xhr) => {
        expect(xhr.response.statusCode).to.eq(200);
      });
    });
  });
});

At this point, I have a pact file that only includes the last interaction for thing-two and not the interaction for thing-one. I believe this is because constructPactFile is excluding "duplicate" interactions based on the test title, which in this case, the test has two interactions under the same test title, so the first one gets excluded/overwritten.

Am I using the Cypress adapter correctly? If so, is there a reason I can only write one interaction per test? Or is this a bug in the adapter?

Thanks!

@kand
Copy link
Author

kand commented Apr 10, 2024

I think the interface would make intuitive sense if the formattedAlias was included in testCaseTitle here:

testCaseTitle: `${testCaseTitle}`,

Which would match the behavior of using cy.usePactWait with an array of aliases.

@nivedhasamy
Copy link

I am facing the same issue. Did you manage to resolve this?

@kand
Copy link
Author

kand commented Apr 24, 2024

Because of the issue in the adapter code I referenced in my last comment, I think the only way to resolve this is to separate the tests. So instead of

Test
- setup scenario A
- test result A
- setup scenario B now that we're in A
- test result B

I split it into two tests:

Test A
- setup scenario A
- test result A

Test B
- setup scenario A
- setup scenario B now that we're in A
- test result B

Kind of a bummer since this is not how Cypress works. Probably better test design though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants