admin管理员组文章数量:1026989
I have a test in my typescript application:
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);
});
}
);
When I pile it into js, there are no errors. But when I run it, I have following error:
TypeError: expect(...).toHaveBeenCalledTimes is not a function
How to test, how many times function of SpyObj was called? Thanks in advance.
I have a test in my typescript application:
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);
});
}
);
When I pile it into js, there are no errors. But when I run it, I have following error:
TypeError: expect(...).toHaveBeenCalledTimes is not a function
How to test, how many times function of SpyObj was called? Thanks in advance.
Share Improve this question edited Aug 23, 2016 at 21:03 Ulad Melekh asked Aug 23, 2016 at 21:00 Ulad MelekhUlad Melekh 9443 gold badges18 silver badges33 bronze badges 02 Answers
Reset to default 4Take a look here , and go to the section of "Other tracking properties"
You can try using the .calls.count()
property.
So your test bees:
expect(subscriber.processNotifyAction.calls.count()).toEqual(2)
Side note - This is of course assuming your version of Jasmine supports this, which it should unless you have a REALLY old version of Jasmine.
toHaveBeenCalledTimes()
was introduced in Jasmine 2.4. Judging by the symptoms - toHaveBeenCalledWith()
did not fail, it looks like you have Jasmine 2.3 or older, upgrade.
I have a test in my typescript application:
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);
});
}
);
When I pile it into js, there are no errors. But when I run it, I have following error:
TypeError: expect(...).toHaveBeenCalledTimes is not a function
How to test, how many times function of SpyObj was called? Thanks in advance.
I have a test in my typescript application:
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);
});
}
);
When I pile it into js, there are no errors. But when I run it, I have following error:
TypeError: expect(...).toHaveBeenCalledTimes is not a function
How to test, how many times function of SpyObj was called? Thanks in advance.
Share Improve this question edited Aug 23, 2016 at 21:03 Ulad Melekh asked Aug 23, 2016 at 21:00 Ulad MelekhUlad Melekh 9443 gold badges18 silver badges33 bronze badges 02 Answers
Reset to default 4Take a look here , and go to the section of "Other tracking properties"
You can try using the .calls.count()
property.
So your test bees:
expect(subscriber.processNotifyAction.calls.count()).toEqual(2)
Side note - This is of course assuming your version of Jasmine supports this, which it should unless you have a REALLY old version of Jasmine.
toHaveBeenCalledTimes()
was introduced in Jasmine 2.4. Judging by the symptoms - toHaveBeenCalledWith()
did not fail, it looks like you have Jasmine 2.3 or older, upgrade.
本文标签: javascriptTypescript Jasmine toHaveBeenCalledTimes() is not a functionStack Overflow
版权声明:本文标题:javascript - Typescript Jasmine toHaveBeenCalledTimes() is not a function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745662587a2161980.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论