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
2d7b9455
Commit
2d7b9455
authored
May 11, 2017
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed promise action binding and simplified callbacks spy
parent
dbab076b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
16 deletions
+11
-16
spec/javascripts/lib/utils/poll_spec.js
spec/javascripts/lib/utils/poll_spec.js
+11
-16
No files found.
spec/javascripts/lib/utils/poll_spec.js
View file @
2d7b9455
...
...
@@ -14,32 +14,27 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
timer
();
};
function
mockServiceCall
(
service
,
response
,
shouldFail
)
{
function
mockServiceCall
(
service
,
response
,
shouldFail
=
false
)
{
const
action
=
shouldFail
?
Promise
.
reject
:
Promise
.
resolve
;
const
responseObject
=
response
;
if
(
!
responseObject
.
headers
)
responseObject
.
headers
=
{};
service
.
fetch
.
calls
.
reset
();
service
.
fetch
.
and
.
callFake
(()
=>
action
(
responseObject
));
service
.
fetch
.
and
.
callFake
(
action
.
bind
(
Promise
,
responseObject
));
}
f
describe
(
'
Poll
'
,
()
=>
{
describe
(
'
Poll
'
,
()
=>
{
const
service
=
jasmine
.
createSpyObj
(
'
service
'
,
[
'
fetch
'
]);
let
callbacks
;
const
callbacks
=
jasmine
.
createSpyObj
(
'
callbacks
'
,
[
'
success
'
,
'
error
'
])
;
beforeEach
(()
=>
{
callbacks
=
{
success
:
()
=>
{},
error
:
()
=>
{},
};
spyOn
(
callbacks
,
'
success
'
);
spyOn
(
callbacks
,
'
error
'
);
afterEach
(()
=>
{
callbacks
.
success
.
calls
.
reset
();
callbacks
.
error
.
calls
.
reset
();
service
.
fetch
.
calls
.
reset
();
});
f
it
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
{
status
:
200
});
it
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
{
status
:
200
}
,
false
);
new
Poll
({
resource
:
service
,
...
...
@@ -53,7 +48,7 @@ fdescribe('Poll', () => {
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
done
();
}
,
0
);
});
});
it
(
'
calls the error callback whe the http request returns an error
'
,
(
done
)
=>
{
...
...
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