I am trying to write test cases for the below code:
async readFile(filename) {
try {
const fileStream = fs.createReadStream(filename);
const rs = readline.createInterface({
input: fileStream,
});
} catch (error) {
throw error.message;
}
}
test case:
await expect(readFile('invalid-file.txt')).to.be.rejectedWith(
"ENOENT, no such file or directory 'invalid-file.txt'",
);
I am getting error for the above test case:
Uncaught Error: ENOENT, no such file or directory 'invalid-file.txt'
at Binding.<anonymous> (node_modules/mock-fs/lib/binding.js:383:15)
How to write test case for catch exceptions?
Note: This test is passing in my local, but failing in Travis.
Thanks in advance.