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

Jest Example assertions never executed #21

Closed
robinglen opened this issue Feb 17, 2017 · 1 comment
Closed

Jest Example assertions never executed #21

robinglen opened this issue Feb 17, 2017 · 1 comment

Comments

@robinglen
Copy link

robinglen commented Feb 17, 2017

#If you check the example: https://github.com/pact-foundation/pact-js/blob/master/examples/jest/__tests__/index.spec.js#L70

it('successfully verifies', done => {
      return getMeDogs({ url, port })
        .then(provider.verify)
        .then(response => {
          expect(response.headers['content-type']).toEqual('application/json');
          expect(response.data).toEqual(EXPECTED_BODY);
          expect(response.status).toEqual(200);
        })
        .then(done, done)
    })

The done happens before the assertions are run, so these tests don't do anything, so it will always pass. If you refactor to look something like:

    it('successfully verifies', done => {
      return getMeDogs({ url, port })
        .then(provider.verify)
        .then(response => {
          expect(response.headers['content-type']).toEqual('application/json');
          expect(response.data).toEqual(EXPECTED_BODY);
          expect(response.status).toEqual(200);
          done();
        }, (error) => {
          console.log(error);
          done();
        })
    })

Now the assertions actually run however response is undefined so the tests fail. After some trial and error I found it was this line .then(provider.verify) made response return undefined. I'm not sure what that actually does but if you remove you get some passing tests.

    it('successfully verifies', done => {
      return getMeDogs({ url, port })
        .then(response => {
          expect(response.headers['content-type']).toEqual('application/json');
          expect(response.data).toEqual(EXPECTED_BODY);
          expect(response.status).toEqual(200);
          done();
        }, (error) => {
          console.log(error);
          done();
        })
    })

The problem with .then(provider.verify) is also true with the mocha test example. So my question is, what is provider.verify doing? Is it needed? If you let me know I can make a PR and fix these examples.

@mefellows
Copy link
Member

I've found this issue also (and actually properly raised it just now under #22). See https://github.com/pact-foundation/pact-js/blob/fix/verify/src/pact.js#L103-L116 for an example fix.

FWIW I'm working on an API cleanup as we speak, I hope to have this sorted in the next week or so.

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