Files
freeCodeCamp/curriculum/test/utils/extract-js-comments.test.js
Oliver Eyton-Williams e139fbcf13 test: update *test* grammar
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2021-10-27 21:29:05 +05:30

36 lines
789 B
JavaScript

const extractJSComments = require('./extract-js-comments');
const someJS = `
// single line comment
/*
a multiline comment
*/
var x = 'y'; // single line comment
var y = '// single line comment';
`;
const someInvalidJS = `const isChange;`;
describe('extractJSComments', () => {
it('should return an object with comment keys and count values', () => {
const commentCounts = {
'single line comment': 2,
'a multiline comment': 1
};
expect(extractJSComments(someJS)).toEqual(commentCounts);
});
it('should throw an informative error if the JS is invalid', () => {
expect(() => extractJSComments(someInvalidJS)).toThrow(
`extract-js-comments could not parse the code below, this challenge has invalid syntax:
${someInvalidJS}
`
);
});
});