1
私たちはテストライブラリのためにモカ、チャイ、シロンに移動しました。ジャスミンから来て、私は約束のテスト方法についてちょっと混乱しています。
私はフォームがサービスを呼び出し、戻り時に、それが正しい状態にユーザーをナビゲートする機能を提出する必要があり:
submit(event, theForm){
event.preventDefault();
if(theForm.$valid){
this.AuthenticationService.authenticateUser({
email: this.email,
password: this.password
}).then((result) => {
this.$state.go('dashboard.home')
});
}
}
は、次の試験であり道の一部を得ている:
it('should submit the login credentials if valid', function(){
var dfd = q.defer(),
promise = dfd.promise;
controller.email = '[email protected]';
controller.password = 'Password123';
sinon.stub(service, 'authenticateUser').returns(promise);
sinon.spy(state, 'go');
sinon.spy(controller, 'submit');
controller.submit(event, theForm);
dfd.resolve();
expect(controller.submit).to.have.been.called;
expect(controller.submit).to.have.been.calledWith(event, theForm);
expect(event.preventDefault).to.have.been.called;
expect(service.authenticateUser).to.have.been.called;
expect(service.authenticateUser).to.have.been.calledWith({
email: controller.email,
password: controller.password
});
expect(state.go).to.have.been.called;
expect(state.go).to.have.been.calledWith('dashboard.home');
});
しかし、state.go
が呼ばれるというアサーションは成立しません。テストをパスするために私は何を変えますか?
Hey @ RyanP13上記の問題を解決しましたか?私も同じ問題に直面しています。コード "authenticateUser"をテストしようとすると約束します.. –