Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Wolfram Kriesing
article-discover-extract-dependencies
Commits
9d808180
Commit
9d808180
authored
Mar 18, 2017
by
Wolfram Kriesing
Browse files
Inject the fetch function too. Now we have control over all the dependencies of this function.
parent
aaf3278c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
src/load-student.spec.js
src/load-student.spec.js
+4
-4
No files found.
src/load-student.spec.js
View file @
9d808180
const
{
assertThat
,
equalTo
}
=
require
(
'
hamjest
'
);
// const { fetch } = require('./backend');
let
fetch
;
const
loadStudent
=
({
studentId
},
dependencies
)
=>
{
const
cache
=
dependencies
.
cache
;
const
fetch
=
dependencies
.
fetch
;
if
(
!
cache
[
studentId
])
{
cache
[
studentId
]
=
fetch
({
studentId
});
}
...
...
@@ -17,9 +17,9 @@ describe('Load a student', () => {
assertThat
(
student
,
equalTo
(
'
student 42
'
));
});
it
(
'
fetch the student if not in the cache
'
,
()
=>
{
le
t
emptyCache
=
{};
fetch
=
()
=>
'
student 23
'
;
const
student
=
loadStudent
({
studentId
:
23
},
{
cache
:
emptyCache
}
);
cons
t
emptyCache
=
{};
const
dependencies
=
{
cache
:
emptyCache
,
fetch
:
()
=>
'
student 23
'
}
;
const
student
=
loadStudent
({
studentId
:
23
},
dependencies
);
assertThat
(
student
,
equalTo
(
'
student 23
'
));
});
});
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