diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-01-23 12:12:18 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-01-23 12:12:18 +0000 |
commit | 33e727de96c0bd4289fa9fb8ff2bea3e0f6a36fd (patch) | |
tree | f14c5802176234fa430901b6818cae77d6ada06f | |
parent | 4dc42845f2ceadcff76a99908220e61610c5b608 (diff) | |
parent | 9e28ca9d4771aa25a496d96a90fd440a233f322b (diff) | |
download | gitlab-ce-33e727de96c0bd4289fa9fb8ff2bea3e0f6a36fd.tar.gz |
Merge branch 'winh-axios-mock-adapter-docs' into 'master'
Document advantages of axios-mock-adapter
See merge request gitlab-org/gitlab-ce!16645
-rw-r--r-- | doc/development/fe_guide/axios.md | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/doc/development/fe_guide/axios.md b/doc/development/fe_guide/axios.md index 34fa684c5d6..dcd8f5cb839 100644 --- a/doc/development/fe_guide/axios.md +++ b/doc/development/fe_guide/axios.md @@ -27,10 +27,23 @@ This exported module should be used instead of directly using `axios` to ensure }); ``` -## Mock axios response on tests +## Mock axios response in tests -To help us mock the responses we need we use [axios-mock-adapter][axios-mock-adapter] +To help us mock the responses we are using [axios-mock-adapter][axios-mock-adapter]. +Advantages over [`spyOn()`]: + +- no need to create response objects +- does not allow call through (which we want to avoid) +- simple API to test error cases +- provides `replyOnce()` to allow for different responses + +We have also decided against using [axios interceptors] because they are not suitable for mocking. + +[axios interceptors]: https://github.com/axios/axios#interceptors +[`spyOn()`]: https://jasmine.github.io/api/edge/global.html#spyOn + +### Example ```javascript import axios from '~/lib/utils/axios_utils'; @@ -54,7 +67,7 @@ To help us mock the responses we need we use [axios-mock-adapter][axios-mock-ada }); ``` -### Mock poll requests on tests with axios +### Mock poll requests in tests with axios Because polling function requires a header object, we need to always include an object as the third argument: |