I have the following pieces of nodejs code:
const watcher = chokidar.watch(path, {
persistent: true
});
watcher
.on('add', path=> {
// func1();
})
.on('change', path=> {
// func2();
})
.on('unlink', path=> {
// func3();
});
I need to use mocha to write some unit test cases to test the above code, but I'm not familiar with mocha and not sure how to trigger these add/change/unlink events. I've tried to use mock-fs, but it seems like it can only simulate the 'add' event. Can somebody help me if you have any idea?
it('should read file when file is added or changed, log error when file is removed', function () {
// on 'add' event
chai.assert.isTrue(func1.isCalled);
// on 'change event
chai.assert.isTrue(func2.isCalled);
// on 'unlink'
chai.assert.isTrue(func3.isCalled);
});