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
Boxiang Sun
gitlab-ce
Commits
d82e709f
Commit
d82e709f
authored
Jan 23, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that axios adapater is restored after mocking
parent
dcb79741
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
app/assets/javascripts/lib/utils/axios_utils.js
app/assets/javascripts/lib/utils/axios_utils.js
+8
-0
spec/javascripts/test_bundle.js
spec/javascripts/test_bundle.js
+10
-0
No files found.
app/assets/javascripts/lib/utils/axios_utils.js
View file @
d82e709f
...
...
@@ -22,3 +22,11 @@ axios.interceptors.response.use((config) => {
});
export
default
axios
;
/**
* @return The adapter that axios uses for dispatching requests. This may be overwritten in tests.
*
* @see https://github.com/axios/axios/tree/master/lib/adapters
* @see https://github.com/ctimmerm/axios-mock-adapter/blob/v1.12.0/src/index.js#L39
*/
export
const
getDefaultAdapter
=
()
=>
axios
.
defaults
.
adapter
;
spec/javascripts/test_bundle.js
View file @
d82e709f
...
...
@@ -6,6 +6,8 @@ import '~/commons';
import
Vue
from
'
vue
'
;
import
VueResource
from
'
vue-resource
'
;
import
{
getDefaultAdapter
}
from
'
~/lib/utils/axios_utils
'
;
const
isHeadlessChrome
=
/
\b
HeadlessChrome
\/
/
.
test
(
navigator
.
userAgent
);
Vue
.
config
.
devtools
=
!
isHeadlessChrome
;
Vue
.
config
.
productionTip
=
false
;
...
...
@@ -59,6 +61,8 @@ beforeEach(() => {
Vue
.
http
.
interceptors
=
builtinVueHttpInterceptors
.
slice
();
});
const
axiosDefaultAdapter
=
getDefaultAdapter
();
// render all of our tests
const
testsContext
=
require
.
context
(
'
.
'
,
true
,
/_spec$/
);
testsContext
.
keys
().
forEach
(
function
(
path
)
{
...
...
@@ -94,6 +98,12 @@ describe('test errors', () => {
it
(
'
has no Vue error
'
,
()
=>
{
expect
(
hasVueErrors
).
toBe
(
false
);
});
it
(
'
restores axios adapter after mocking
'
,
()
=>
{
if
(
getDefaultAdapter
()
!==
axiosDefaultAdapter
)
{
fail
(
'
axios adapter is not restored! Did you forget a restore() on MockAdapter?
'
);
}
});
});
// if we're generating coverage reports, make sure to include all files so
...
...
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