我在我的打字稿應用測試:打字稿茉莉花toHaveBeenCalledTimes()不是一個函數
it("Should send current state when new subscriber is added (watching over file)",
() => {
runs(() => {
flag = false;
subscriber = createSpyObj<IPathWatchSubscriber>("PathWatchSubscriberMock", ["processNotifyAction"]);
subscriber2 = createSpyObj<IPathWatchSubscriber>("PathWatchSubscriberMock", ["processNotifyAction"]);
pathWatch.subscribe(subscriber);
pathWatch.watch(filePath);
pathWatch.subscribe(subscriber2);
w(() => { flag = true; });
});
waitsFor((): boolean => {
return flag;
}, "failure", chokidarOperationDelay);
runs(() => {
expect(subscriber.processNotifyAction).toHaveBeenCalledWith(expectedNotifyAction);
expect(subscriber.processNotifyAction).toHaveBeenCalledTimes(2);
expect(subscriber2.processNotifyAction).toHaveBeenCalledWith(expectedNotifyAction);
});
}
);
當我把它編譯成JS,沒有錯誤。但是,當我運行它,我有以下錯誤:SpyObj的
TypeError: expect(...).toHaveBeenCalledTimes is not a function
如何測試,多少次函數被調用? 在此先感謝。
謝謝,您的解決方法適用於我。還有一件事,我從CreateSpyObject切換到SpyOn,然後使用「.calls.count()」。 –