For example:
import { msw } from "msw";
msw.post(
"http://localhost:3000/cats",
(req, res, { status, set, delay, json }) => {
return res(status(404), delay(10000), json({ errorMessage: `no cats :(` }));
}
);
msw.start();
It seems that the normalizeMask() function is turning the following URL http://localhost:3000/cats into ^http://localhost(\w+)/cats\/?$ which will not match successfully since the colon isn't alpha-numeric:
A very good call. To be honest, the entire mask matching could be improved.
Previously, it needed to have some weird stringification to evaluate the expressions on the Service Worker side. Now SW-client communicates over the message channel, and thus the routes matching is delegated to the library module.
I think I can get rid of stringification and treating RegExps as they are.
P.S. Stringification is also used to store the mocking route as the key in this.routes of MSW class.
I will update the functionality in the next patch release so it will use matchPath (similar to one in react-router) and remove any stringification of route masks. It will, however, remove the support for wildcard * in the routes, I would need to add that later.
I've tested the latest changes with your use case and it works okay as "http://localhost:3000/cats" doesn't transform into RegExp.
Published 0.2.2. The issue should be resolved now. Mocking both http://localhost:3000/cats and even http://localhost:*/cats works as expected.
Could you please verify that it works with the latest version?
@kettanaito seems to work 馃憤 thanks for looking into this! 馃槃
Most helpful comment
@kettanaito seems to work 馃憤 thanks for looking into this! 馃槃