0
브로드 캐스트 이벤트 발생시 컨트롤러가 모달을 여는 지 테스트하려고합니다. 코드는 잘 작동하지만 기대는 항상 실패단위 테스트 작성 방법 각도 방송 이후 메서드 호출
it('should open model on idleStart', function() {
$scope.$on('idleStart', function(){
expect(dsModalSpy).toHaveBeenCalled();
});
$scope.$broadcast('idleStart');
});
나는 그것이 때문에 방송의 비동기 특성 실패 가정합니다. 컨트롤러가 모달을 열 시간이 없었습니다. 그래서 다() 메소드에 추가하고 그것은 지금 통과 된 말했다의 setTimeout 기능
it('should open model on idleStart', function (done) {
$scope.$on('idleStart', function(){
setTimeout(function(){
expect(dsModalSpy).toHaveBeenCalled();
done();
}, 500);
});
$scope.$broadcast('idleStart');
});
에 넣어,하지만 난 디버거 문에 넣어 그래서 나는 의심을 가지고 있었다. setTimeout의 코드는 테스트가 성공적으로 완료되었다고 표시 될 때까지 실행되지 않습니다.
it('should open modal on idleStart', function (done) {
$scope.$on('idleStart', function(){
setTimeout(function(){
debugger //This code is run after the test says it is completed and passed successfully.
done();
}, 500);
});
$scope.$broadcast('idleStart');
});
done 인수를 done 함수에 추가하여 done 함수가 호출 될 때까지 완료되지 않았다는 것을 알릴 것이라고 생각했습니다.
감사합니다.