我有一个类,它使用Chokidar,现在需要用茉莉来测试它。这就是chokidar加入的方法:
public watch(path: string) {
var watchOptions: chokidar.WatchOptions = <chokidar.WatchOptions> {
persistent: true
};
this.watcher = chokidar.watch(path, watchOptions);
this.watcher.on("add", (fileName: string, stats: fs.Stats) => {
this.sendNotifyAction(new NotifyAction(PathEvent.Add, fileName));
}).on("change", (fileName: string, stats: fs.Stats) => {
this.sendNotifyAction(new NotifyAction(PathEvent.Change, fileName));
})
}我想在我的测试中做这样的事情:
it("Should send notification, when internal directory is added", () => {
runs(() => {
flag = false;
pathWatch.watch(dirPath);
//TRIGGER chokidar on.add event??
//spyOn(pathWatch.watcher, "on").and.callFake((params) => {
// flag = true;
//});
});
waitsFor((): boolean => {
return flag;
}, "failure", 5000);
runs(() => {
var expectedNotifyAction = new NotifyAction(PathEvent.Add, notificationInternalDirPath);
expect(subscriber.processNotifyAction).toHaveBeenCalledWith(expectedNotifyAction);
});
});问题是我不知道如何模仿Chokidar事件。任何帮助都是非常感谢的。
发布于 2016-08-22 17:48:19
观察者实例继承自EventEmitter,因此您可以在它上调用.emit() (虽然我不确定如何/如果使用TypeScript):
pathWatch.watcher.emit('add', PATH, STATS);https://stackoverflow.com/questions/39069169
复制相似问题