Skip to content

Commit

Permalink
test updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Jul 3, 2024
1 parent e4ff829 commit 2bd2c5d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 1 addition & 2 deletions scripts/casestudies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = async function buildCaseStudiesList() {
)
}
} catch (err) {
console.error(err);
throw err;
throw new Error(err);
}
};
7 changes: 2 additions & 5 deletions tests/casestudies/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ describe('buildCaseStudiesList', () => {
expect(writeFile).toHaveBeenCalledWith(caseStudiesJsonPath, JSON.stringify([jsonContent1, jsonContent2]));
});

test('should log and throw an error if an error occurs', async () => {
test('should throw an error if an error occurs', async () => {
const error = new Error('Test error');
readdir.mockRejectedValue(error);
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

await expect(buildCaseStudiesList()).rejects.toThrow(error);
await expect(buildCaseStudiesList()).rejects.toThrow(`Error: ${error.message}`);

expect(consoleErrorSpy).toHaveBeenCalledWith(error);
consoleErrorSpy.mockRestore();
});
});

0 comments on commit 2bd2c5d

Please sign in to comment.