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

Allow access to express-style path parameters in mocked endpoints #656

Open
ryanscottaudio opened this issue Feb 9, 2023 · 0 comments
Open

Comments

@ryanscottaudio
Copy link

ryanscottaudio commented Feb 9, 2023

When adding a mock for an express-style path (e.g. express:/example/:foo/:bar, there is no built-in way to access the parsed values for foo and bar:

const mockedEndpoint = (url, opts) => {
  // we should be able to use { foo: <whatever>, bar: <whatever> } here without additional parsing
};

fetchMock.get('express:/example/:foo/:bar', mockedEndpoint);

fetch('/example/foovalue/barvalue'); // we would have access to { foo: 'foovalue', bar: 'barvalue' } in mockedEndpoint 

We're giving fetchMock.get enough information (the matching express-style pattern and the URL itself) that it should be able to parse out what foo and bar are and pass them to the callback (potentially as a third argument?).

This issue was called out in #300 but either wasn't addressed at all or was addressed but in a too-opaque-for-me-to-understand way.

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

No branches or pull requests

1 participant