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

Question on provider.verify() in consumer test? #65

Closed
MichaelSu1983 opened this issue Jul 18, 2017 · 4 comments
Closed

Question on provider.verify() in consumer test? #65

MichaelSu1983 opened this issue Jul 18, 2017 · 4 comments

Comments

@MichaelSu1983
Copy link

In examples/e2e/test/consumer.spec.js, I find the below test.

describe('when interacting with Animal Service', () => {
    it('should validate the interactions and create a contract', () => {
      return provider.verify()
    })
  })

Question: I don't understand what "provider.verify()" does? Is this mandatory to be included in a test? or I can remove it. After I remove it, I can still see log and pact file are generated and test is run as well.

I have a test like this:

describe('CRUD operations:', () => {
    describe('POST',() => {
      before((done) => {
        provider.addInteraction().then(() => { done(); });
      });

      it('POST', (done) => {
            done();
          })
          .catch(done);
      });

      it('successfully verifies', () => provider.verify());
    });

    describe('PUT',() => {
      before((done) => {
        provider.addInteraction().then(() => { done(); });
      });

      it('PUT', (done) => {
            done();
          })
          .catch(done);
      });

      it('successfully verifies', () => provider.verify());
    });

  });
@mefellows
Copy link
Member

Thanks @MichaelSu1983, perhaps our documentation is not very clear on this.

The provider.verify() step is key to the Pact tests. Verify checks that the interactions you've registered and expected to be present were in fact called by the function you were testing (e.g. it('POST', ...)).

Without it, you are registering expectations and creating a contract with those expectations in it, but you aren't sure if your code is actually a) calling the API(s) or b) sending the right data or c) using the data that is coming back. This is marginally better than pure documentation.

@MichaelSu1983
Copy link
Author

Thanks @mefellows for the confirmation. Now I see.

So one more thing, is the way I structure tests correct?

should I return provider.verify() like the example, or leave "it('successfully verifies', () => provider.verify());" as separate test? or I can write it in one case "afterEach(() => provider.verify());"?

@mefellows
Copy link
Member

It's a promise so you return it or explicitly complete it or you might not get the feedback if it passed or failed.

In terms of where it should go, It's up to you really, and your style.

It's probably nicer to have the verify() called in the same test scope so you know if it fails which test it relates to but some people like to keep them separate for readability etc.

@lirantal
Copy link
Contributor

I understand the confusion here. I think we need to explain it better in the example and the docs.

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

3 participants