Skip to content

Improve mock error breadcrumbs #1999

@renzor-fist

Description

@renzor-fist

This would solve...

More quickly understanding which mocked endpoint is not matching on MockNotMatchedError

MockNotMatchedError: Mock dispatch not matched for method 'POST': subsequent request to origin https://discord.com was not allowed (net.connect disabled)

🤔☝️ what endpoint is this not matching for???

The implementation should look like...

In mock-utils.js>getMockDispatch, there are a series of matchedMockDispatches checks.

let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path }) => matchValue(path, resolvedPath))

if (matchedMockDispatches.length === 0) {
  throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`)
}

// Match method
matchedMockDispatches = matchedMockDispatches.filter(({ method }) => matchValue(method, key.method))
if (matchedMockDispatches.length === 0) {
  throw new MockNotMatchedError(`Mock dispatch not matched for method '${key.method}'`)
}

If the first check passes, we know we've matched resolvedPath. Therefore, we can add this to the error messages in subsequent checks so that its easier to track down the MockNotMatchedError source.

For example, if we don't match the request method, the error could be:

  throw new MockNotMatchedError(`Mock dispatch not matched for method '${key.method}' on path '${resolvedPath}'`)

Then, in our original error message, we'd know our POST request isn't matching on path /api/channels/123/messages

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions