jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Examples for mocks set up using regular expressions #85

Closed benjspriggs closed 4 years ago

benjspriggs commented 4 years ago

The documentation specifies that you can provide a string or a RegExp to set up a mock, but there aren't any easily accessible examples.

Would it be possible to include 1 or 2 examples in the README or wiki for easier access?

Thanks a bunch in advance for this wonderful library - it's been super helpful for what I've been needing it for!

jameslnewell commented 4 years ago

Hi @benjspriggs!

Sorry, I haven't got round to updating the docs yet (feel free to submit a PR!), but if you were wondering how to use a RegExp, this example should get you started:

Return a mock response for all URLs ending in .json

mock.get(/\.json$/, {
  body: '{"data":{"id":"abc-123"}}'
});

Thanks for your kind words!