首页 > 其他 > 详细

[Unit Testing] Based on input value, spyOn function

时间:2016-02-05 01:29:48      阅读:228      评论:0      收藏:0      [点我收藏+]
        describe( ‘Forgot Password: with username‘, ()=> {
            let dirElementInput;
            beforeEach( ()=> {
                // Find the input control:
                dirElementInput = directiveElem.find(‘input‘);

                // Set some text!
                angular.element(dirElementInput).val(‘ahto.simakuutio@gmail.com‘).trigger(‘input‘);
                $scope.$apply();
            } );

            it( ‘should have username‘, ()=> {
                expect(directiveCtrl.user.username ).toEqual(‘ahto.simakuutio@gmail.com‘);
            } );

            it(‘should call UserService\‘s forgotPassword function‘, ()=>{

                spyOn(UserService, ‘forgotPassword‘);
                angular.element( directiveElem.find( ‘button‘ )[ 2 ] )
                       .click();
                expect(UserService.forgotPassword).toHaveBeenCalled();
            });
        } );

        describe(‘Forgot password: without username‘, ()=>{
            let dirElementInput;
             beforeEach( ()=> {
                 dirElementInput = directiveElem.find(‘input‘);
                 angular.element(dirElementInput).val(‘‘).trigger(‘input‘);
                 $scope.$apply();
             });

            it(‘should have empty username value‘, ()=>{
                expect(directiveCtrl.user.username).toBeUndefined();
            });

            it(‘should not call UserService\‘s ForgotPassword function‘, ()=>{

                spyOn(UserService, ‘forgotPassword‘);
                angular.element( directiveElem.find( ‘button‘ )[ 2 ] )
                       .click();
                expect(UserService.forgotPassword).not.toHaveBeenCalled();
            })
        });

 

[Unit Testing] Based on input value, spyOn function

原文:http://www.cnblogs.com/Answer1215/p/5176682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!