You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a GET request with the url in the following format: api/v1/rest/collection?startDate>="(ISO 8601 string)"&startDate<"(ISO 8601 string)"
I want to let it pass through (to a default baseURL) when the startDate range is outside the specific range I am mocking.
The simplest way to enable this is by allowing a matcher function as an argument to onXXX methods.
To support other complex mocking scenarios it could receive the (mutable) config object that the reply function also receives.
This is how I would use it:
varaxios=require('axios')varAxiosMockAdapter=require('axios-mock-adapter')axios.default.defaults.baseURL='http://url.to.test.api'varmock=newAxiosMockAdapter(axios,{delayResponse: 100// ms})vardata=[]// mocked data ordered by startDatemock.onGet(function(config){varstart// parse "startDate>=..." from query of config.urlvarend// parse "startDate<..." from query of config.urlif(config.url.indexOf('api/v1/rest/collection?')===0&&data[0].startDate<=start&&data[data.length-1].startDate>=end){config.start=startconfig.end=endreturntrue}returnfalse}).reply(function(config){console.log('mock '+config.url)return[200,data.filter(x=>x.startDate>=config.start&&x.startDate<config.end)]})mock.onAny().passThrough()
The text was updated successfully, but these errors were encountered:
I have a GET request with the url in the following format:
api/v1/rest/collection?startDate>="(ISO 8601 string)"&startDate<"(ISO 8601 string)"
I want to let it pass through (to a default baseURL) when the startDate range is outside the specific range I am mocking.
The simplest way to enable this is by allowing a matcher function as an argument to
onXXX
methods.To support other complex mocking scenarios it could receive the (mutable) config object that the reply function also receives.
This is how I would use it:
The text was updated successfully, but these errors were encountered: