ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

Add onNoMatch option #237

Closed ostapenko-me closed 4 years ago

ostapenko-me commented 4 years ago

This merge request solves problem from #217

I added onNoMatch option to MockAdapter constructor. If you set onNoMatch option to passthrough all requests would be forwarded over network by default

// Mock all requests to /foo with HTTP 200, but forward
// any others requests to server
var mock = new MockAdapter(axiosInstance, { onNoMatch: 'passthrough' });

mock
  .onAny('/foo').reply(200);

Also i added new bundlesize check in testing pipeline. It checks size of minified bundle on each yarn test run.

Simple checklist:

ostapenko-me commented 4 years ago

@ctimmerm, can you check and merge this pr?

ctimmerm commented 4 years ago

Thanks, this looks great :+1:

One thing I'd like to change is how the option is named. I think next to doing a 404 or passthrough when no match is found there are also other possible desired actions. If the option would be named onNoMatch or something similar (with "passthrough" being one option), we can later easily expand it to also have other options (e.g. "throw" to throw an exception).

ostapenko-me commented 4 years ago

@ctimmerm, done.

I renamed passThroughByDefault flag to onNoMatch option. Can you check this pr?

ctimmerm commented 4 years ago

Thanks!