Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alfa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
alfa
Commits
3fc01df1
Commit
3fc01df1
authored
5 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-3563 fix tests and new mocking function
parent
a24ad607
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
alfa-client/libs/test-utils/src/lib/mocking.spec.ts
+26
-0
26 additions, 0 deletions
alfa-client/libs/test-utils/src/lib/mocking.spec.ts
alfa-client/libs/test-utils/src/lib/mocking.ts
+0
-10
0 additions, 10 deletions
alfa-client/libs/test-utils/src/lib/mocking.ts
with
26 additions
and
10 deletions
alfa-client/libs/test-utils/src/lib/mocking.spec.ts
0 → 100644
+
26
−
0
View file @
3fc01df1
import
{
Mock
,
mock
}
from
'
@alfa-client/test-utils
'
;
describe
(
'
mock
'
,
()
=>
{
class
TestService
{
methodTestService
()
{}
}
class
ExtendedService
extends
TestService
{
prop
:
string
=
'
test
'
;
methodExtendedService
()
{}
}
const
mockedService
:
Mock
<
ExtendedService
>
=
mock
(
ExtendedService
);
it
(
'
should mock methods of a class
'
,
()
=>
{
expect
(
mockedService
.
methodTestService
).
toBeDefined
();
});
it
(
'
should mock methods of inherited class
'
,
()
=>
{
expect
(
mockedService
.
methodExtendedService
).
toBeDefined
();
});
it
(
'
should not mock non-function properties
'
,
()
=>
{
expect
(
mockedService
.
prop
).
toBeUndefined
();
});
});
This diff is collapsed.
Click to expand it.
alfa-client/libs/test-utils/src/lib/mocking.ts
+
0
−
10
View file @
3fc01df1
...
@@ -47,16 +47,6 @@ export function mock<T>(service: Type<T>): Mock<T> {
...
@@ -47,16 +47,6 @@ export function mock<T>(service: Type<T>): Mock<T> {
return
mockValue
;
return
mockValue
;
}
}
export
function
mock2
<
T
>
(
service
:
Type
<
T
>
):
Mock
<
T
>
{
return
<
Mock
<
T
>>
Object
.
getOwnPropertyNames
(
service
.
prototype
).
reduce
(
(
mockValue
,
key
)
=>
({
...
mockValue
,
[
key
]:
jest
.
fn
(),
}),
<
any
>
{},
);
}
function
isFunctionDescriptor
(
prototype
:
object
)
{
function
isFunctionDescriptor
(
prototype
:
object
)
{
return
(
key
:
string
)
=>
{
return
(
key
:
string
)
=>
{
const
descriptor
:
PropertyDescriptor
=
Object
.
getOwnPropertyDescriptor
(
prototype
,
key
);
const
descriptor
:
PropertyDescriptor
=
Object
.
getOwnPropertyDescriptor
(
prototype
,
key
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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