One of my functions involves retrieving file content.
export function getFileContent(path: string): any {
const content = readFileSync(path);
return JSON.parse(content.toString());
}
If I need to verify that calling getFileContent(meteFile)
results in a specific error, I can use the following:
expect(getFileContent(metaFile)).to.throw(new SyntaxError('Unexpected token } in JSON at position 82'));
But is there a way to confirm that the expression doesn't produce any errors?
I attempted this approach:
expect(getFileContent(metaFile)).not.to.throw();
However, it resulted in an error message:
AssertionError: expected { Object (...) } to be a function
So, how can I effectively validate that the function call does not encounter any errors?