[TypeScript] typescript-axios: Added possibility to add custom axios instance.#1274
Conversation
This comes in handy if you want to use mocks in tests.
|
@nicokoenig does the enhancement look good to you? |
3 similar comments
|
I just added a alignment to fetch regarding the custom instance but somehow my comment, my commit and everything else doesn't appear here? github bug? last commit should be: |
07c5b30 to
c7e4f7d
Compare
|
Ok time to clean up this PR a bit: https://blog.github.com/2018-10-21-october21-incident-report/ :) |
|
@nicokoenig could you recheck after my c7e4f7d commit? I updated the api according to the fetch example so its more consistent. Due to the github outage we had a race-condition. |
|
@sruehl quick question if you don't mind. Is it correct to say that your change is backward-compatible (non-breaking change) as you just added an optional parameter to the API method signature? |
|
@wing328 yep that's the idea (the supplied instance is optional). |
|
@nicokoenig thanks for the review. @sruehl thanks for the enhancement. |
|
@sruehl thanks for the PR, which is included in the v3.3.2 release: https://twitter.com/oas_generator/status/1057649626101112832 |
…instance. (OpenAPITools#1274) * typescript-axios: Added possibility to add custom axios instance. This comes in handy if you want to use mocks in tests. * typescript-axios: aligned to fetch API for custom instance
This comes in handy if you want to use mocks in tests.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.master,3.4.x,4.0.x. Default:master.Description of the PR
This PR adds the possibility to supply a custom axios instance to the typescript-axios clients.
This then can be used to supply a axios mock adapter in unit-tests:
const mock = new MockAdapter(axiosInstance, { delayResponse: 600 }).To test this feature a simple test-case has been added which just supplies the global axios instance.
Updated remark (2018/10/22): One thing we could do different is to supply the instance via configuration or constructor parameter so one doesn't need to supply the instance on every call.
cc: @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09)