Skip to content

Mock requests based on query parameters #2347

Closed Answered by kettanaito
kobenguyent asked this question in Q&A
Discussion options

You must be logged in to vote

Hi. You can implement the abstraction you want by moving it down to the response resolver that has the access to the actual query parameter values.

function addInteractionToMockServer(interaction) {
  handlers.push(
    // 1. Do NOT add query parameters to "_path". They will be ignored.
    http[interaction.request.method.toLowerCase()](`${_path}`, ({ request }) => {
      const url = new URL(request.url)
      const actualQuery = url.searchParams

      // 2. Compare "actualQuery" and your "interaction.request.queryParams"
      // to determine if this intercepted request should be matched.
      // Implement this logic yourself.
      if (matches(actualQuery, inteeraction.request.queryP…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants