Skip to content

Commit

Permalink
test added for err
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Nov 23, 2024
1 parent 4fcdea8 commit e1a16c1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/markdown/check-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,24 @@ describe('Frontmatter Validator', () => {
expect(mockConsoleLog).not.toHaveBeenCalledWith(expect.stringContaining('Errors in file reference/specification/skipped.md'));
mockConsoleLog.mockRestore();
});

it('logs and rethrows error when an exception occurs while processing a file', async () => {
const filePath = path.join(tempDir, 'invalid.md');
await fs.writeFile(filePath, `---\ntitle: Valid Title\n---`);

const mockReadFile = jest.spyOn(fs, 'readFile').mockRejectedValue(new Error('Test readFile error'));

try {
await checkMarkdownFiles(tempDir, validateBlogs);
} catch (err) {
expect(mockConsoleError).toHaveBeenCalledWith(
expect.stringContaining(`Error processing file invalid.md:`),
expect.any(Error)
);
expect(err.message).toBe('Test readFile error');
}

mockReadFile.mockRestore();
});

});

0 comments on commit e1a16c1

Please sign in to comment.