I have the following function:
var fs = require('fs');
function Writer(path, content) {
this.path = path;
this.content = content;
this.process = function () {
fs.writeFile(
this.path,
this.content,
function (error) {
if (error) {
throw new Error('Something went wrong during writing');
}
}, 'utf-8')
};
}
module.exports = Writer;
With the this test:
it('test if writing fails ', function () {
var writer = new Writer(
'/data/configurations/ab/ba/abba/test.json',
'content'
);
expect(function() {
writer.process()
}).toThrowError("Something went wrong during writing");
})
So this is expected to fail because there is no file to write. Then the library FS is throwing an Error which is uncaught.
Here is the output from the test:
Started
.....F
Failures:
1) writer test test if writing fails
Message:
Expected function to throw an Error.
Stack:
Error: Expected function to throw an Error.
at Object.<anonymous> (/vagrant/project/tests/utils/file/writerTest.js:42:6)
6 specs, 1 failure
Finished in 0.198 seconds
/vagrant/project/node_modules/mock-fs/lib/binding.js:1060
throw new FSError('ENOENT', filepath);
Error: ENOENT, no such file or directory '/vagrant/project/node_modules/jasmine/node_modules/exit'
at Binding.<anonymous> (/vagrant/project/node_modules/mock-fs/lib/binding.js:1060:13)
so the library is throwing and error and the toThrowError doesn't get it. Does someone have an idea how to solve it or what is my mistake?
Aucun commentaire:
Enregistrer un commentaire