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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
be6f20d5
Commit
be6f20d5
authored
5 years ago
by
Martin Hanzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test false passes on unmocked requests
parent
663b7bb4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
8 deletions
+21
-8
spec/frontend/mocks/ce/lib/utils/axios_utils.js
spec/frontend/mocks/ce/lib/utils/axios_utils.js
+2
-1
spec/frontend/mocks/mocks_helper_spec.js
spec/frontend/mocks/mocks_helper_spec.js
+3
-4
spec/frontend/mocks/node/jquery.js
spec/frontend/mocks/node/jquery.js
+3
-1
spec/frontend/mocks_spec.js
spec/frontend/mocks_spec.js
+13
-2
No files found.
spec/frontend/mocks/ce/lib/utils/axios_utils.js
View file @
be6f20d5
...
...
@@ -6,9 +6,10 @@ axios.isMock = true;
axios
.
defaults
.
adapter
=
config
=>
{
const
message
=
`Unexpected unmocked request:
${
JSON
.
stringify
(
config
,
null
,
2
)}
\n`
+
'
Consider using the `axios-mock-adapter` in tests.
'
;
'
Consider using the `axios-mock-adapter`
module
in tests.
'
;
const
error
=
new
Error
(
message
);
error
.
config
=
config
;
global
.
fail
(
error
);
throw
error
;
};
...
...
This diff is collapsed.
Click to expand it.
spec/frontend/mocks/mocks_helper_spec.js
View file @
be6f20d5
/* eslint-disable global-require
, promise/catch-or-return
*/
/* eslint-disable global-require */
import
path
from
'
path
'
;
...
...
@@ -126,9 +126,8 @@ describe('mocks_helper.js', () => {
it
(
'
survives jest.isolateModules()
'
,
done
=>
{
jest
.
isolateModules
(()
=>
{
const
axios2
=
require
(
'
~/lib/utils/axios_utils
'
).
default
;
expect
(
axios2
.
get
(
'
http://gitlab.com
'
))
.
rejects
.
toThrow
(
'
Unexpected unmocked request
'
)
.
then
(
done
);
expect
(
axios2
.
isMock
).
toBe
(
true
);
done
();
});
});
...
...
This diff is collapsed.
Click to expand it.
spec/frontend/mocks/node/jquery.js
View file @
be6f20d5
...
...
@@ -4,9 +4,11 @@ const $ = jest.requireActual('jquery');
// Fail tests for unmocked requests
$
.
ajax
=
()
=>
{
throw
new
Error
(
const
err
=
new
Error
(
'
Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.
'
,
);
global
.
fail
(
err
);
throw
err
;
};
// jquery is not an ES6 module
...
...
This diff is collapsed.
Click to expand it.
spec/frontend/mocks_spec.js
View file @
be6f20d5
...
...
@@ -3,11 +3,22 @@ import axios from '~/lib/utils/axios_utils';
describe
(
'
Mock auto-injection
'
,
()
=>
{
describe
(
'
mocks
'
,
()
=>
{
it
(
'
~/lib/utils/axios_utils
'
,
()
=>
expect
(
axios
.
get
(
'
http://gitlab.com
'
)).
rejects
.
toThrow
(
'
Unexpected unmocked request
'
));
let
failMock
;
beforeEach
(()
=>
{
failMock
=
jest
.
spyOn
(
global
,
'
fail
'
).
mockImplementation
();
});
it
(
'
~/lib/utils/axios_utils
'
,
done
=>
{
expect
(
axios
.
get
(
'
http://gitlab.com
'
)).
rejects
.
toThrow
(
'
Unexpected unmocked request
'
);
setImmediate
(()
=>
{
expect
(
failMock
).
toHaveBeenCalledTimes
(
1
);
done
();
});
});
it
(
'
jQuery.ajax()
'
,
()
=>
{
expect
(
$
.
ajax
).
toThrow
(
'
Unexpected unmocked
'
);
expect
(
failMock
).
toHaveBeenCalledTimes
(
1
);
});
});
});
This diff is collapsed.
Click to expand it.
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