2
私の角2のアプリケーションでは、私の主なメソッド内の私の外部メソッド(依存関係)がそれに応じて呼び出されているかどうかをテストします。例えば 外部メソッド(角2)を呼び出すメソッドのジャスミンスパイ
、ここでClass ServiceA
{
constructor(
private serviceB : ServiceB
){}
//How do I test this method to make sure it does what it should ?
mainMethod()
{
//External method
this.serviceB.otherMethod();
this.sideMethod();
}
sideMethod()
{
//Do something
}
}
Class ServiceB
{
constructor(){}
otherMethod()
{
//Do something
}
}
は、私がこれまで
it('On otherMethod returns false, do something',
inject([ServiceA, ServiceB], (serviceA: ServiceA, serviceB: ServiceB) => {
spyOn(serviceB, 'otherMethod').and.returnValue(false);
spyOn(serviceA, 'sideMethod');
spyOn(serviceA, 'mainMethod').and.callThrough();
expect(serviceB.otherMethod()).toHaveBeenCalled();
expect(serviceA.sideMethod()).toHaveBeenCalled();
expect(serviceA.mainMethod()).toHaveBeenCalled();
}));
上記のコードから、試してみたものだ、私はというエラーを得た
にオブジェクトを見つけることができませんでしたspy on otherMethod()
ここで何が間違っていますか?
を私はこの質問、おかげでとにかく男を投稿分後にそれを考え出しました! –