BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0e372f96
Commit
0e372f96
authored
May 23, 2017
by
Fatih Acet
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'winh-recent-searches-service-spec' into 'master'
Handle Promise rejections in RecentSearchesService spec See merge request !11206
parents
348afcd5
999f71f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
22 deletions
+30
-22
recent_searches_service_spec.js
.../filtered_search/services/recent_searches_service_spec.js
+30
-22
No files found.
spec/javascripts/filtered_search/services/recent_searches_service_spec.js
View file @
0e372f96
/* eslint-disable promise/catch-or-return */
import
RecentSearchesService
from
'~/filtered_search/services/recent_searches_service'
;
import
RecentSearchesServiceError
from
'~/filtered_search/services/recent_searches_service_error'
;
import
AccessorUtilities
from
'~/lib/utils/accessor'
;
describe
(
'RecentSearchesService'
,
()
=>
{
...
...
@@ -22,11 +21,9 @@ describe('RecentSearchesService', () => {
fetchItemsPromise
.
then
((
items
)
=>
{
expect
(
items
).
toEqual
([]);
done
();
})
.
catch
((
err
)
=>
{
done
.
fail
(
'Shouldn
\'
t reject with empty localStorage key'
,
err
);
});
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'should reject when unable to parse'
,
(
done
)
=>
{
...
...
@@ -34,19 +31,24 @@ describe('RecentSearchesService', () => {
const
fetchItemsPromise
=
service
.
fetch
();
fetchItemsPromise
.
then
(
done
.
fail
)
.
catch
((
error
)
=>
{
expect
(
error
).
toEqual
(
jasmine
.
any
(
SyntaxError
));
done
();
});
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'should reject when service is unavailable'
,
(
done
)
=>
{
RecentSearchesService
.
isAvailable
.
and
.
returnValue
(
false
);
service
.
fetch
().
catch
((
error
)
=>
{
expect
(
error
).
toEqual
(
jasmine
.
any
(
Error
));
done
();
});
service
.
fetch
()
.
then
(
done
.
fail
)
.
catch
((
error
)
=>
{
expect
(
error
).
toEqual
(
jasmine
.
any
(
Error
));
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'should return items from localStorage'
,
(
done
)
=>
{
...
...
@@ -56,8 +58,9 @@ describe('RecentSearchesService', () => {
fetchItemsPromise
.
then
((
items
)
=>
{
expect
(
items
).
toEqual
([
'foo'
,
'bar'
]);
done
();
});
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
describe
(
'if .isAvailable returns `false`'
,
()
=>
{
...
...
@@ -65,12 +68,17 @@ describe('RecentSearchesService', () => {
RecentSearchesService
.
isAvailable
.
and
.
returnValue
(
false
);
spyOn
(
window
.
localStorage
,
'getItem'
);
RecentSearchesService
.
prototype
.
fetch
();
});
it
(
'should not call .getItem'
,
()
=>
{
expect
(
window
.
localStorage
.
getItem
).
not
.
toHaveBeenCalled
();
it
(
'should not call .getItem'
,
(
done
)
=>
{
RecentSearchesService
.
prototype
.
fetch
()
.
then
(
done
.
fail
)
.
catch
((
err
)
=>
{
expect
(
err
).
toEqual
(
new
RecentSearchesServiceError
());
expect
(
window
.
localStorage
.
getItem
).
not
.
toHaveBeenCalled
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
...
...
@@ -105,11 +113,11 @@ describe('RecentSearchesService', () => {
RecentSearchesService
.
isAvailable
.
and
.
returnValue
(
true
);
spyOn
(
JSON
,
'stringify'
).
and
.
returnValue
(
searchesString
);
RecentSearchesService
.
prototype
.
save
.
call
(
recentSearchesService
);
});
it
(
'should call .setItem'
,
()
=>
{
RecentSearchesService
.
prototype
.
save
.
call
(
recentSearchesService
);
expect
(
window
.
localStorage
.
setItem
).
toHaveBeenCalledWith
(
localStorageKey
,
searchesString
);
});
});
...
...
@@ -117,11 +125,11 @@ describe('RecentSearchesService', () => {
describe
(
'if .isAvailable returns `false`'
,
()
=>
{
beforeEach
(()
=>
{
RecentSearchesService
.
isAvailable
.
and
.
returnValue
(
false
);
RecentSearchesService
.
prototype
.
save
();
});
it
(
'should not call .setItem'
,
()
=>
{
RecentSearchesService
.
prototype
.
save
();
expect
(
window
.
localStorage
.
setItem
).
not
.
toHaveBeenCalled
();
});
});
...
...
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