-1

I tried several approach to match this specific pattern of the url:

https://app.launchdarkly.com/sdk/goals/123123123

so the 123123123 will be always changing.also for some reason its making a OPTION call beside another GET call every time. Not sure why and that's likely another story...

nock return error like:

Error: Error: Nock: No match for request {
      "method": "OPTIONS",
   "url": "https://app.launchdarkly.com/sdk/goals/123123123",
  "headers": {
    "origin": "http://localhost",
    "access-control-request-method": "GET",
    "access-control-request-headers": "X-LaunchDarkly-User-Agent",
    "user-agent": "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/16.5.3",
    "host": "app.launchdarkly.com",
    "content-length": 0
  }
}

nock is not recognizing the pattern if I do (note that I am copying the same pattern as a GET as well)

nock('https://app.launchdarkly.com')
    .persist()
    .defaultReplyHeaders({
        'access-control-allow-origin': '*',
        'access-control-allow-headers': '*',
        'access-control-allow-credentials': 'true',
    })
    .options('/sdk/goals.*$/')
    .reply(200, mockLDExperiments);

or

nock('https://app.launchdarkly.com')
    .persist()
    .defaultReplyHeaders({
        'access-control-allow-origin': '*',
        'access-control-allow-headers': '*',
        'access-control-allow-credentials': 'true',
    })
    .options('/sdk/goals/**/*')
    .reply(200, mockLDExperiments);

or

nock('https://app.launchdarkly.com')
    .persist()
    .defaultReplyHeaders({
        'access-control-allow-origin': '*',
        'access-control-allow-headers': '*',
        'access-control-allow-credentials': 'true',
    })
    .options('/sdk/goals')
    .reply(200, mockLDExperiments);

any idea how to write the correct path matcher so I can allow this segment scenario gets picked up by nock?

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121

1 Answers1

0

Nock supports Regex path matching. It seems you're attempting something similar with globs, however, if a string is provided Nock only does exact matching. Docs

For your case, something like this should get you going.

nock('https://app.launchdarkly.com')
  ...
  .options(/^\/sdk\/goals\//)
  ...
Matt R. Wilson
  • 7,268
  • 5
  • 32
  • 48