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

Improve mock error breadcrumbs #1999

Open
renzor-fist opened this issue Mar 10, 2023 · 1 comment
Open

Improve mock error breadcrumbs #1999

renzor-fist opened this issue Mar 10, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@renzor-fist
Copy link

renzor-fist commented Mar 10, 2023

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

@renzor-fist renzor-fist added the enhancement New feature or request label Mar 10, 2023
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants