javascript - Typescript Jasmine toHaveBeenCalledTimes() is not a function - Stack Overflow

I have a test in my typescript application:it("Should send current state when new subscriber is ad

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 0
Add a ment  | 

2 Answers 2

Reset to default 4

Take 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745662588a4638926.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信