This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
codeAbility Sharing Platform
Manage
Activity
Members
Labels
Plan
Issues
41
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
development
sharing
codeAbility Sharing Platform
Commits
b844bd97
Commit
b844bd97
authored
1 year ago
by
Michael Breu
Browse files
Options
Downloads
Patches
Plain Diff
starting with jest test
parent
e684bcfd
Branches
Branches containing commit
2 merge requests
!231
New Deployment into production and update gitlab
,
!225
Resolve "Collections mehr hervorheben"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/webapp/app/exercise/service/exercise.service.spec.ts
+68
-0
68 additions, 0 deletions
...main/webapp/app/exercise/service/exercise.service.spec.ts
with
68 additions
and
0 deletions
src/main/webapp/app/exercise/service/exercise.service.spec.ts
0 → 100644
+
68
−
0
View file @
b844bd97
import
{
HttpClientModule
}
from
'
@angular/common/http
'
;
import
{
HttpClientTestingModule
,
HttpTestingController
}
from
'
@angular/common/http/testing
'
;
import
{
TestBed
}
from
'
@angular/core/testing
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
TranslateModule
}
from
'
@ngx-translate/core
'
;
import
{
ApplicationConfigService
}
from
'
app/core/config/application-config.service
'
;
import
{
LocalStorageService
,
SessionStorageService
}
from
'
ngx-webstorage
'
;
import
{
ExerciseService
}
from
'
./exercise.service
'
;
describe
(
'
ExerciseService
'
,
()
=>
{
let
service
:
ExerciseService
;
let
httpMock
:
HttpTestingController
;
let
applicationConfigService
:
ApplicationConfigService
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
HttpClientTestingModule
,
HttpClientModule
,
TranslateModule
.
forRoot
(),
RouterTestingModule
],
declarations
:
[],
providers
:
[
ApplicationConfigService
,
LocalStorageService
,
SessionStorageService
],
});
applicationConfigService
=
TestBed
.
inject
(
ApplicationConfigService
);
service
=
TestBed
.
inject
(
ExerciseService
);
httpMock
=
TestBed
.
inject
(
HttpTestingController
);
});
it
(
'
should inject
'
,
()
=>
{
expect
(
service
).
toBeTruthy
();
});
it
(
'
test Caching
'
,
()
=>
{
let
isInvoked443
=
0
;
let
isInvoked444
=
0
;
service
.
loadExercise
(
'
443
'
).
subscribe
(()
=>
{
isInvoked443
++
;
});
service
.
loadExercise
(
'
444
'
).
subscribe
(()
=>
{
isInvoked444
++
;
});
expect
(
isInvoked443
).
toEqual
(
0
);
// still waiting for response
expect
(
isInvoked444
).
toEqual
(
0
);
// still waiting for response
const
testRequest443
=
httpMock
.
expectOne
({
method
:
'
GET
'
,
url
:
applicationConfigService
.
getEndpointFor
(
'
api/exercise/443
'
),
});
const
testRequest444
=
httpMock
.
expectOne
({
method
:
'
GET
'
,
url
:
applicationConfigService
.
getEndpointFor
(
'
api/exercise/444
'
),
});
testRequest443
.
flush
({
kaese
:
'
kaese
'
,
});
testRequest444
.
flush
({
kaese
:
'
kaese
'
,
});
expect
(
isInvoked443
).
toEqual
(
1
);
expect
(
isInvoked444
).
toEqual
(
1
);
service
.
loadExercise
(
'
444
'
).
subscribe
(()
=>
{
isInvoked444
++
;
});
expect
(
isInvoked444
).
toEqual
(
3
);
// result was returned immediately from cache
expect
(
isInvoked443
).
toEqual
(
2
);
httpMock
.
expectNone
({});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment