[Unit Testing] Based on input value, spyOn function
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Unit Testing] Based on input value, spyOn function相关的知识,希望对你有一定的参考价值。
describe( ‘Forgot Password: with username‘, ()=> { let dirElementInput; beforeEach( ()=> { // Find the input control: dirElementInput = directiveElem.find(‘input‘); // Set some text! angular.element(dirElementInput).val(‘[email protected]‘).trigger(‘input‘); $scope.$apply(); } ); it( ‘should have username‘, ()=> { expect(directiveCtrl.user.username ).toEqual(‘[email protected]‘); } ); 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的主要内容,如果未能解决你的问题,请参考以下文章
Testing ovn manually based on LXD (by quqi99)
Testing ovn manually based on LXD (by quqi99)
[Unit Testing] Mock a Node module's dependencies using Proxyquire