Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
9e28ca9d
Commit
9e28ca9d
authored
Jan 23, 2018
by
Winnie Hellmann
Committed by
Filipa Lacerda
Jan 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document advantages of axios-mock-adapter
parent
4dc42845
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
doc/development/fe_guide/axios.md
doc/development/fe_guide/axios.md
+16
-3
No files found.
doc/development/fe_guide/axios.md
View file @
9e28ca9d
...
...
@@ -27,10 +27,23 @@ This exported module should be used instead of directly using `axios` to ensure
});
```
## Mock axios response
o
n tests
## Mock axios response
i
n 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
o
n tests with axios
### Mock poll requests
i
n tests with axios
Because polling function requires a header object, we need to always include an object as the third argument:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment