2016-08-23 5 views
0

ではありません。活字体ジャスミンtoHaveBeenCalledTimesは()私はtypescriptですアプリケーションでテストを持っている機能

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

どのようにテストするために、何回関数が呼び出されました:私はそれを実行したときしかし、私はエラーを次がありますか? ありがとうございます。

答えて

1

はあなたが.calls.count()プロパティを使用して試すことができます

を見hereを取り、そして「その他の追跡プロパティ」のセクションに移動します。

だからあなたのテストは、次のようになります。 expect(subscriber.processNotifyAction.calls.count()).toEqual(2)

サイドノート - これは、ジャスミンのバージョンを想定し、もちろんです、それはあなたがジャスミンの本当に古いバージョンを持っている必要がありますしない限り、これはこれをサポートしています。

+0

ありがとう、あなたの回避策は私のために働く。もう一つ、私はCreateSpyObject からSpyOnに切り替え、 ".calls.count()"を使用しました。 –

関連する問題