fix(tests): add validation of comment translations (#41537)
This commit is contained in:
committed by
GitHub
parent
654d66186e
commit
0d3158d4f4
77
curriculum/test/utils/extract-script-js-comments.test.js
Normal file
77
curriculum/test/utils/extract-script-js-comments.test.js
Normal file
@ -0,0 +1,77 @@
|
||||
/* global expect */
|
||||
const extractScriptJSComments = require('./extract-script-js-comments');
|
||||
|
||||
const inlineComments = `<body>
|
||||
Some text
|
||||
<script>
|
||||
|
||||
// comment 1
|
||||
|
||||
var x = 'y';
|
||||
|
||||
// comment 2
|
||||
|
||||
// comment 1
|
||||
|
||||
</script>
|
||||
</body>
|
||||
`;
|
||||
|
||||
const multilineComments = `<body>
|
||||
Some text
|
||||
<script>
|
||||
|
||||
/*
|
||||
comment 1
|
||||
*/
|
||||
var x = 'y';
|
||||
|
||||
/* comment 2 */
|
||||
|
||||
/* comment 1 */
|
||||
|
||||
</script>
|
||||
</body>
|
||||
`;
|
||||
|
||||
const outsideScript = `<body>
|
||||
Some text
|
||||
<script>
|
||||
|
||||
// comment 1
|
||||
|
||||
var x = 'y';
|
||||
|
||||
// comment 2
|
||||
|
||||
// comment 1
|
||||
|
||||
</script>
|
||||
|
||||
// comment 2
|
||||
</body>
|
||||
`;
|
||||
|
||||
describe('extractScriptJSComments', () => {
|
||||
it('should catch inline comments', () => {
|
||||
const commentCounts = {
|
||||
'comment 1': 2,
|
||||
'comment 2': 1
|
||||
};
|
||||
expect(extractScriptJSComments(inlineComments)).toEqual(commentCounts);
|
||||
});
|
||||
it('should catch multiline comments', () => {
|
||||
const commentCounts = {
|
||||
'comment 1': 2,
|
||||
'comment 2': 1
|
||||
};
|
||||
expect(extractScriptJSComments(multilineComments)).toEqual(commentCounts);
|
||||
});
|
||||
it('should ignore comments outside script tags', () => {
|
||||
const commentCounts = {
|
||||
'comment 1': 2,
|
||||
'comment 2': 1
|
||||
};
|
||||
expect(extractScriptJSComments(outsideScript)).toEqual(commentCounts);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user