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
Aug 15, 2019
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;
...
@@ -6,9 +6,10 @@ axios.isMock = true;
axios
.
defaults
.
adapter
=
config
=>
{
axios
.
defaults
.
adapter
=
config
=>
{
const
message
=
const
message
=
`Unexpected unmocked request:
${
JSON
.
stringify
(
config
,
null
,
2
)}
\n`
+
`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
);
const
error
=
new
Error
(
message
);
error
.
config
=
config
;
error
.
config
=
config
;
global
.
fail
(
error
);
throw
error
;
throw
error
;
};
};
...
...
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
'
;
import
path
from
'
path
'
;
...
@@ -126,9 +126,8 @@ describe('mocks_helper.js', () => {
...
@@ -126,9 +126,8 @@ describe('mocks_helper.js', () => {
it
(
'
survives jest.isolateModules()
'
,
done
=>
{
it
(
'
survives jest.isolateModules()
'
,
done
=>
{
jest
.
isolateModules
(()
=>
{
jest
.
isolateModules
(()
=>
{
const
axios2
=
require
(
'
~/lib/utils/axios_utils
'
).
default
;
const
axios2
=
require
(
'
~/lib/utils/axios_utils
'
).
default
;
expect
(
axios2
.
get
(
'
http://gitlab.com
'
))
expect
(
axios2
.
isMock
).
toBe
(
true
);
.
rejects
.
toThrow
(
'
Unexpected unmocked request
'
)
done
();
.
then
(
done
);
});
});
});
});
...
...
spec/frontend/mocks/node/jquery.js
View file @
be6f20d5
...
@@ -4,9 +4,11 @@ const $ = jest.requireActual('jquery');
...
@@ -4,9 +4,11 @@ const $ = jest.requireActual('jquery');
// Fail tests for unmocked requests
// Fail tests for unmocked requests
$
.
ajax
=
()
=>
{
$
.
ajax
=
()
=>
{
throw
new
Error
(
const
err
=
new
Error
(
'
Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.
'
,
'
Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.
'
,
);
);
global
.
fail
(
err
);
throw
err
;
};
};
// jquery is not an ES6 module
// jquery is not an ES6 module
...
...
spec/frontend/mocks_spec.js
View file @
be6f20d5
...
@@ -3,11 +3,22 @@ import axios from '~/lib/utils/axios_utils';
...
@@ -3,11 +3,22 @@ import axios from '~/lib/utils/axios_utils';
describe
(
'
Mock auto-injection
'
,
()
=>
{
describe
(
'
Mock auto-injection
'
,
()
=>
{
describe
(
'
mocks
'
,
()
=>
{
describe
(
'
mocks
'
,
()
=>
{
it
(
'
~/lib/utils/axios_utils
'
,
()
=>
let
failMock
;
expect
(
axios
.
get
(
'
http://gitlab.com
'
)).
rejects
.
toThrow
(
'
Unexpected unmocked request
'
));
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()
'
,
()
=>
{
it
(
'
jQuery.ajax()
'
,
()
=>
{
expect
(
$
.
ajax
).
toThrow
(
'
Unexpected unmocked
'
);
expect
(
$
.
ajax
).
toThrow
(
'
Unexpected unmocked
'
);
expect
(
failMock
).
toHaveBeenCalledTimes
(
1
);
});
});
});
});
});
});
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