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
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
9c223756
Commit
9c223756
authored
Mar 27, 2019
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helpers for HTML fixtures to Jest
parent
346f7027
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
spec/frontend/helpers/fixtures.js
spec/frontend/helpers/fixtures.js
+20
-6
No files found.
spec/frontend/helpers/fixtures.js
View file @
9c223756
/* eslint-disable import/prefer-default-export, global-require, import/no-dynamic-require */
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
...
...
@@ -7,16 +5,32 @@ import { ErrorWithStack } from 'jest-util';
const
fixturesBasePath
=
path
.
join
(
process
.
cwd
(),
'
spec
'
,
'
javascripts
'
,
'
fixtures
'
);
export
function
get
JSON
Fixture
(
relativePath
,
ee
=
false
)
{
const
absolutePath
=
path
.
join
(
fixturesBasePath
,
ee
?
'
ee
'
:
''
,
relativePath
);
export
function
getFixture
(
relativePath
)
{
const
absolutePath
=
path
.
join
(
fixturesBasePath
,
relativePath
);
if
(
!
fs
.
existsSync
(
absolutePath
))
{
throw
new
ErrorWithStack
(
`Fixture file
${
relativePath
}
does not exist.
Did you run bin/rake karma:fixtures?`
,
get
JSON
Fixture
,
getFixture
,
);
}
return
require
(
absolutePath
);
return
fs
.
readFileSync
(
absolutePath
,
'
utf8
'
);
}
export
const
getJSONFixture
=
relativePath
=>
JSON
.
parse
(
getFixture
(
relativePath
));
export
const
resetHTMLFixture
=
()
=>
{
document
.
body
.
textContent
=
''
;
};
export
const
setHTMLFixture
=
(
htmlContent
,
resetHook
=
afterEach
)
=>
{
document
.
body
.
outerHTML
=
htmlContent
;
resetHook
(
resetHTMLFixture
);
};
export
const
loadHTMLFixture
=
(
relativePath
,
resetHook
=
afterEach
)
=>
{
const
fileContent
=
getFixture
(
relativePath
);
setHTMLFixture
(
fileContent
,
resetHook
);
};
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