Skip to content

Expecting calls to the same path in the same test #23

Description

@ybce

I have a scenario where I am setting up expectations to call an external service twice (mocking that in my tests using mock-https-server), one which returns an empty array and one that returns a response.

something like this:

  expectGetResourceByParamX (queryParams, statusCode, body) {
    this.server.on({
      method: 'GET',
      path: '/v1/resource',
      filter: (req) => {
       // filter code
        return true
      },
      reply: {
        status: statusCode,
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify(body)
      }
    })
  }

  expectGetResourceByParamY (queryParams, statusCode, body) {
    this.server.on({
      method: 'GET',
      path: '/v1/resource',
      filter: (req) => {
       // filter code
        return true
      },
      reply: {
        status: statusCode,
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify(body)
      }
    })
  }

The only difference is what query params I use on that same exact path, however when setting up the test this seems to cause an issue since the handlers have the same path and the requests that come in are processed by the wrong handler. I looked at the library code but can't see an obvious place where this can be fixed.

Any ideas on how this sort of problem can be solved (if it can be) using this library or is this some sort of limitation of the library.

Thank You.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions