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

Parentheses in request URL handled differently between pretender and MSW #15

Open
mrloop opened this issue Dec 20, 2023 · 1 comment
Open

Comments

@mrloop
Copy link
Contributor

mrloop commented Dec 20, 2023

MSW expects parentheses to be escaped in URLs but pretender does not. This prevents mirage-msw being a drop in replacement. Currently in my mirage setup I'm using a helper function to escape URL strings that contain parentheses if the test suite is running using mirage-msw. Migrating large number on mirage endpoint, small PR by small PR so need to support both MSW and pretender while migrating.

export default function mswEscapeUrl(stringUrl) {
  if (ENV.useMsw) {
    return stringUrl.replaceAll('(', '\\(').replaceAll(')', '\\)');
  }
  return stringUrl;
}

Here's the MSW test and mock showing this behaviour

@mrloop
Copy link
Contributor Author

mrloop commented Dec 20, 2023

I guess this in an incompatibility between path matching in MSW using path-to-regexp and supporting regex URL matching and pretender using route-recognizer and not supporting regex.

@mrloop mrloop changed the title Parathesis in request URL handled differently between pretender and MSW Parentheses in request URL handled differently between pretender and MSW Dec 20, 2023
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